• «
  • 1
  • 2
  • 3
  • »
  • Pages: 1/3     Go
主题 : 路过顺便指点下platform_get_resource 获取资源问题??先谢了 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
楼主  发表于: 2009-08-14 16:25

 路过顺便指点下platform_get_resource 获取资源问题??先谢了

platform_driver
platform_device
已经注册成功  
cat proc/ iomem 下也有
/sys/ bus/ platform/drivers
/sys/ bus/ platform/devices
也有
就是在probe 中platform_get_resource无法获取资源

我是把驱动直接编译进内核里 下到开发板上 出现
---[ end trace 4dc5c39dd2c09aa6 ]---
Kernel panic - not syncing: Attempted to kill init!
就死掉了   怎么回事??
one more time~ one more chance~
级别: 侠客
UID: 7776
精华: 1
发帖: 73
金钱: 675 两
威望: 503 点
综合积分: 166 分
注册时间: 2009-07-28
最后登录: 2020-06-08
1楼  发表于: 2009-08-14 16:29
看一个简单的 platform_device 的例子

static struct resource s3c_rtc_resource[] = {
    [0] = {
        .start = S3C24XX_PA_RTC,
        .end   = S3C24XX_PA_RTC + 0xff,
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = IRQ_RTC,
        .end   = IRQ_RTC,
        .flags = IORESOURCE_IRQ,
    },
    [2] = {
        .start = IRQ_TICK,
        .end   = IRQ_TICK,
        .flags = IORESOURCE_IRQ
    }
};

struct platform_device s3c_device_rtc = {
    .name          = "s3c2410-rtc",
    .id          = -1,
    .num_resources      = ARRAY_SIZE(s3c_rtc_resource),
    .resource      = s3c_rtc_resource,
};

不知道你的platform_device里面的resource资源填写正确没有~
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
2楼  发表于: 2009-08-14 16:34
回复真快 在这先谢谢 “superfight”  !!
以下是我的  感觉没什么问题  还请指点下!!

  static struct resource s3c_keybus_resource[] = {
    [0] = {
        .start = S3C2410_CS3,
        .end   = S3C2410_CS3 + 3,
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = S3C2410_CS3 + 4,
        .end   = S3C2410_CS3 + 4 + 3,
        .flags = IORESOURCE_MEM,
    },
    
};


struct platform_device s3c_device_keybus = {
    .name       = "keybus",
    .id     = 0,
    .num_resources  = ARRAY_SIZE(s3c_keybus_resource),
    .resource   = s3c_keybus_resource,

};
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
3楼  发表于: 2009-08-14 16:38
就S3C2440A而言,不管是哪个Memory的bank,都不会出现S3C2410_CS3 + 3这种map,你在map什么?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
4楼  发表于: 2009-08-14 16:42
我想写总线驱动  我参照dm9000 写的
db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);

映射 ioremap      db->io_addr,db->io_data
---------------------------------------------
dm9000 devs里写的
/* DM9000 */
static struct resource s3c_dm9k_resource[] = {
    [0] = {
        .start = S3C2410_CS4,
        .end   = S3C2410_CS4 + 3,
        .flags = IORESOURCE_MEM,
    },
    [1] = {
        .start = S3C2410_CS4 + 4,
        .end   = S3C2410_CS4 + 4 + 3,
        .flags = IORESOURCE_MEM,
    },
    [2] = {
        .start = IRQ_EINT7,
        .end   = IRQ_EINT7,
        .flags = IORESOURCE_IRQ | IRQF_TRIGGER_RISING,
    }

};

static struct dm9000_plat_data s3c_dm9k_platdata = {
    .flags      = DM9000_PLATF_16BITONLY,
};

struct platform_device s3c_device_dm9k = {
    .name       = "dm9000",
    .id     = 0,
    .num_resources  = ARRAY_SIZE(s3c_dm9k_resource),
    .resource   = s3c_dm9k_resource,
    .dev        = {
        .platform_data = &s3c_dm9k_platdata,
    }
};

我没用使用中断 就没添加进去
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
5楼  发表于: 2009-08-14 16:56
我的如果蔽掉 platform_get_resource  相关的函数 再编译 就可以了 ,给我的感觉就是这个 platform_get_resource  引起的,但我也找了 也没 有占用的 只有cs8900 网卡是 使用bank3的  ,但start 是 19000000 开始的 应该不影响  我也换过 bank5 但事实不行?奇怪了  
顺便多问下devs里的 id 的值 “ 0和1” 是怎么确定的?
.id     = 0,
.id     = -1,

还请班主 和各位路过的朋友指点!!tks!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
6楼  发表于: 2009-08-14 16:59
把你的驱动源代码和内核启动的串口输出信息贴出来
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
7楼  发表于: 2009-08-14 17:03
可能会有些乱码!
以下是我的串口输出信息------------

Enter your selection?g                      
Copy linux kernel from 0x00050000 to 0x30008000, size = 0x00200000 ... done                                                                          
zImage magic = 0x016f2818                        
Se魎p li顄x parameters at 0x30000100                                    
linux command line is: "noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySA                                                                                
C0"  
MACH_TYPE = 782              
NOW, Booting Linux......                        
Uncompressing Linux.............................................................                                                                                
......................................................... done, booting the kern                                                                                
el.  
Linux version 2.6.29-FriendlyARM (root@localhost.localdomain) (gcc version 4.3.2                                                                                
(Sourcery G++燣ite 2008q3-72) ) #48 Thu Aug 13 17:12:06 CST 2009                                                                
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177                                                        
CPU: VIVT data cache, VIVT instruction cache                                            
Machine: FriendlyARM Mini2440 development board                                              
ATAG_INITRD is deprecated; please update your bootloader.                                                        
Memory policy: ECC disabled, Data cache writeback                                                
CPU S3C2440A (id 0x32440001)                            
S3C24XX Clocks, (c) 2004 Simtec Electronics                                          
S3C244X: core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz                                                                    
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL o                                                
Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 16256                                                                          
Kernel command line: noinitrd root=/dev/mtdblock2 init=/linuxrc console=ttySAC0                                                                              
irq: clearing subpending status 00000003                                        
irq: clearin?subpending status 00000002                                        
PID hash table entries: 256 (order: 8, 1024 bytes)                                                  
Console: colour dummy device 80x30                                  
console [ttySAC0] enabl錮                        
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)                                                            
Inode-cache hash table en魊ies: 4096 (order: 2, 16384 bytes)                                                            
Memory: 64MB = 64MB total                        
Memory: 60992KB available (3376K code, 376?data, 124K init)                                                            
SLUB: Genslabs=12, HWal間n=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1                                                                      
Calibrating delay loop... 201.93 BogoMIPS (lpj=504832)                                                      
Mount-cache hash table entries: 512                                  
CPU: Testing write buffer coherency: ok                                      
net_namespace: 296 bytes                        
NET: Registered protocol family 16                                  
S3C2440: Initialising architecture                                  
S3C2440: IRQ Support                    
S3C24XX DMA Driver, (c) 2003-2004,2006 Simtec Electronics                                                        
DMA channel 0 at c4808000, irq 33                                
DMA channel 1 at c4808040, irq 34                                
DMA channel 2 at c4808080, irq 35                                
DMA channel 3 at c48080c0, irq 36                                
S3C244X: Clock Support, DVS off                              
bio: create slab <bio-0> at 0                            
SCSI subsystem initialized                          
usbcore: registered n鍂 interface driver usbfs                                              
usbcore: registered new interface driver hub                                            
usbcore: regist錼ed new device driver usb                                        
NET: Registered protocol family 2                                
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)                                                              
TCP established hash table entries: 2048 (order: 2, 16384 bytes)                                                                
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)                                                        
TCP: Hash tables configured (established 2048 bind 2048)                                                        
TCP reno registered                  
NET: Registered protocol family 1                                
yaffs Jul 24 2009 10:18:52 Installing.                                      
msgmni has been set to 119                          
io scheduler noop registered (default)                                      
Console: switching to colour frame buffer device 100x30                                                      
fb0: s3c2410fb frame buffer device                                  
backlight       initialized                          
leds    initialized                  
keybus Ethernet Driver, V1.0                            
Unable to handle kernel NULL pointer dereference at virtual address 00000008                                                                            
pgd = c0004000              
[00000008] *pgd=00000000                        
Internal error: Oo                
Modules linked in:                  
CPU: 0    Not tainted  (2.6.29-FriendlyARM #48)                                              
PC is at keybus_probe+0x34/0x9c                              
LR is at keybus_probe+0x30/0x9c                              
pc : [<c02936c0>]    lr : [<c02936bc>]    psr: 60000013                                                      
sp : c381de20  ip : 00000001  fp : c381de34                                          
r10: c38318a0  r9 : c03ca734  r8 : c03857a0                                          
r7 : c0157ec8  r6 : c0384fa0  r5 : c0379170  r4 : 00000000                                                          
r3 : 00000200  r2 :?0000000  r1 : 00000001  r0 : c0379e84                                                          
Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel                                                                  
Control: c000717f  Table: 30004000  DAC: 00000017                                                
Process swapper (pid: 1, stack limit = 0xc381c268)                                                  
Stack: (0xc381de20 to 0xc381e000)                                
de20: c0379178 c0379178 c381de44 c381de38 c0158ca8 c029369c c381de7?c381de48                                                                            
de40: c0157db0 c0158c98 00000000 c0379178 c0379200 c0384fa0 c0157ec8 c03857a0                                                                            
de60: c00157c0 c38318a0 c381de94 c381de78 c0157f50 c0157d10 00000000 c381de98                                                                            
de80: c0384fa0 c0157ec8 c381debc c381de98 c0157658 c0157ed8 c38035b8 c03791a8                                                                            
dea0: 00000000 c0384fa0 00000000 c0384fa0 c381decc c381dec0 c0157c10 c0157604                                                                            
dec0: c381defc c381ded0 c0156fd8 c0157c00                                      
dee0: 00000000 c381c000 00000000 c039fac0 c381df1c c381df00 c0158140 c0156e44                                                                            
df00: c001c6f0燾001c4fc 00000000 c381c000 c381df2c c381df20 c0159018 c01580e8                                                                            
df20: c381df3c c381df30 c00157e4 c0158fbc c381dfcc c381df40 c0027284 c00157d0                                                                            
df40: c381df8e c3830500 c037e20c c03?760 00000050 00000000 c381df84 c381df68                                                                            
df60: c00c2900 c00c274c c381df84 c3831120 c00c2b04 c381df8e c381dfb4 c381df88                                                                            
df80: c0060b58 c00c2984 c01568c8 3038ef70 00000000 00000000 00000055 c037e338                                                                            
dfa0: c001c878 c001c6f0 c001c4fc c001c878 00000                                              
dfc0: c381dff4 c381dfd0 c0008404 c0027258 00000000 00000001 00000000 00000000                                                                            
dfe0: 00000000 00000000 00000000 c381dff8 c003cd78 c0008384 00000000 00000000                                                                            
Backtrace:          
[<c029368c>] (keybus_probe+0x0/0x9c) from [<c0158ca8>] (platform_drv_probe+0x20/                                                                                
0x24)    
r5:c0379178 r4:c0379178                        
[<c0158c88>] (platform_drv_probe+0x0/0x24) from [<c0157db0>] (dr関er_probe_devic                                                                                
e+0xb0/0x1c8)            
[<c0157d00>] (driver_probe_device+0x0/0x1c8) from [<c0157f50>] (__driver_attach+                                                                                
0x88/0x8c)          
[<c0157ec8>] (__鋜iver_attach+0x0/0x8c) from [<c015                            
/0x90)
r7:c0157ec8 r6:?384fa0 r5:c381de98 r4:00000000
[<c01575f4>] (bus_for_each_dev+0x0/0x90) from [<c0157c10>] (driver_attach+0x20/0
x28)
r7:c0384fa0 r6:00000000 r5:c0384fa0 r4:00000000
[<c0157bf0>] (driver_attach+0x0/0x28) from [<c0156fd8>] (bus_add_driver+0x1a4/0x
228)
[<c0156e34>] (bus_ad鋉driver+0x0/0x228) from [<c0158140>] (driver_register+0x68/
0x13c)
[<c01580d8>] (driver_register+0x0/0x13c) from [<c0159018>] (platform_driver_regi
ster+0x6c/0x88)
r7:c381c000 r6:00000000 r5:c001c4fc r4:c001c6f0
[<c0158fac>] (platform_driver_register+0x0/0x88) from [<c00157e4>] (keybus_init+
0x24/0x38)
[<c00157c0>] (keybus_init+0x0/0x38) from [<c0027284>] (__exception_text_end+0x3c
/0x1bc)
[<c0027248>] (__exception_text_end+0x0/0x1bc) from [<c0008404>] (kernel_init+0x9
0/0xfc)
[<c0008374>] (kernel_init+0x0/0xfc) from [<c003cd78>] (do_exit+0x0/0x750)
r6:00000000 r5:00000000 r4:00000000
Code: e58ec010 e1a05000 ebfb1537 e3a04000 (e5840008)
---[ end trace 4dc5c39dd2c09aa6 ]---
Kernel panic - not syncing: Attempted to kill init!

到这就死掉了
级别: 新手上路
UID: 6079
精华: 0
发帖: 34
金钱: 305 两
威望: 191 点
综合积分: 68 分
注册时间: 2009-05-19
最后登录: 2010-08-09
8楼  发表于: 2009-08-14 17:11
以下是我的源代码
------------------------------
#include <linux/module.h>//
#include <linux/ioport.h>//
//#include <linux/netdevice.h>
//#include <linux/etherdevice.h>
#include <linux/init.h>//
#include <linux/skbuff.h>
#include <linux/spinlock.h>
#include <linux/crc32.h>
#include <linux/mii.h>
#include <linux/ethtool.h>
#include <linux/delay.h>//
#include <linux/platform_device.h>//
#include <linux/irq.h>//

#include <linux/miscdevice.h>
#include <linux/fs.h>//
//#include <linux/srting/h>

#include <asm/delay.h>
#include <asm/irq.h>//
#include <asm/io.h>

#include <mach/regs-mem.h>//

#include  <linux/mini2440_keybus.h>

/* Board/System/Debug information/definition ---------------- */

#define CARDNAME    "keybus"
#define DRV_VERSION    "1.0"


/* Structure/enum declaration ------------------------------- */
typedef struct board_info {

    void __iomem    *io_addr;    /* Register I/O base address */
    void __iomem    *io_data;    /* Data I/O address */
//    struct device    *dev;         /* parent device */
    struct resource    *addr_res;   /* resources found */
    struct resource    *data_res;
    struct resource    *addr_req;   /* resources requested */
    struct resource    *data_req;
} board_info_t;


/* keybus_release_board
*
* release a board, and any mapped resources
*/

static void
keybus_release_board(struct platform_device *pdev, struct board_info *db)
{
    /* unmap our resources */

    iounmap(db->io_addr);
    iounmap(db->io_data);

    /* release the resources */

    release_resource(db->data_req);
    kfree(db->data_req);

    release_resource(db->addr_req);
    kfree(db->addr_req);
}

static int s3c_keybus_open(struct inode *inode, struct file *file)
{
    /*istruct board_info  *db;

    printk("keybus open ok , writeb 0xaa and 0x55");
    writeb(0xAA, db->io_addr);
    udelay(200);
    udelay(200);
    udelay(200);
    writeb(0x55, db->io_addr);
    */
    return 0;
}



static int s3c_keybus_release(struct inode *inode, struct file *file)
{
    

    return 0;
}


static const struct file_operations s3c_keybus_fops =
{
    .owner        = THIS_MODULE,
/*  .write        = s3c_keybus_write,*/
/*    .ioctl        = s3c_keybus_ioctl,*/
    .open        = s3c_keybus_open,
    .release    = s3c_keybus_release,
};

static struct miscdevice s3c_keybus_miscdev =
{
    .minor        = KEY_BUS,    
    .name        = "keyubs",
    .fops        = &s3c_keybus_fops,
};

#define res_size(_r)(((_r)->end - (_r)->start) +1)
/*
* Search keybus board, allocate space and register it
*/
static int __devinit
keybus_probe(struct platform_device *pdev)
{
    struct board_info *db;    /* Point a board information structure */
    int ret = 0;
    int iosize;


    __raw_writel(0x2210d110,S3C2410_BWSCON);
    __raw_writel(0x1f7c,S3C2410_BANKCON3);
/*    
    unsigned int oldval_bwscon = *(volatile unsigned int *)S3C2410_BWSCON;
    unsigned int oldval_bankcon3 = *(volatile unsigned int *)S3C2410_BANKCON3;

    *((volatile unsigned int *)S3C2410_BWSCON) =
            (oldval_bwscon & ~(3<<16)) | S3C2410_BWSCON_DW3_8 | S3C2410_BWSCON_WS3 | S3C2410_BWSCON_ST3;
    *((volatile unsigned int *)S3C2410_BANKCON3) = 0x1f7c;
*/
//    memset(db,0,sizeof(*db));
/*
    db->dev = &pdev->dev;
*/    

    db->addr_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
    db->data_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);


    if (db->addr_res == NULL || db->data_res == NULL ) {
        printk(KERN_ERR "keybus: can't get keybus device resource.\n");
        ret = -ENOENT;
        goto out;
    }

/*
    iosize = res_size(db->addr_res);
    db->addr_req = request_mem_region(db->addr_res->start, iosize,
                      pdev->name);

    if (db->addr_req == NULL) {
         printk(KERN_ERR "keybus: cannot claim db->addr_req.\n");
        ret = -EIO;
        goto out;
    }

    db->io_addr = ioremap(db->addr_res->start, iosize);

    if (db->io_addr == NULL) {
         printk(KERN_ERR "keybus: failed to ioremap db->io_addr.\n");
        ret = -EINVAL;
        goto out;
    }

    iosize = res_size(db->data_res);
    db->data_req = request_mem_region(db->data_res->start, iosize,
                      pdev->name);

    if (db->data_req == NULL) {
         printk(KERN_ERR "keybus: cannot claim db->data_req .\n");
        ret = -EIO;
        goto out;
    }

    db->io_data = ioremap(db->data_res->start, iosize);

    if (db->io_data == NULL) {
         printk(KERN_ERR "keybus: failed to iomemp db->io_data .\n");
        ret = -EINVAL;
        goto out;
    }
*/
/*
      ret = misc_register(&s3c_keybus_miscdev);
    if (ret == 0)
            printk("S3C2440 keybus misc_register sucess\n");
    else   printk("s3c2440 keybus misc_register failure\n");    
*/
    return 0;

out:
/*
    *(volatile unsigned int *)S3C2410_BWSCON   = oldval_bwscon;
    *(volatile unsigned int *)S3C2410_BANKCON3 = oldval_bankcon3;

    dev_err(db->dev, "not found (%d).\n", ret);
*/
    printk(KERN_ERR "keybus: probe failed!\n");

    keybus_release_board(pdev, db);
    return ret;

}


static int __devexit
keybus_drv_remove(struct platform_device *pdev)
{    
    struct board_info *db;    
    keybus_release_board(pdev, db);
    return 0;
}


static struct platform_driver keybus_driver = {
    .driver    = {
        .name    = "keybus",
        .owner     = THIS_MODULE,
    },
    .probe   = keybus_probe,
    .remove  = __devexit_p(keybus_drv_remove),
/*    .suspend = keybus_drv_suspend,*/
/*    .resume  = keybus_drv_resume,*/
};

static int __init
keybus_init(void)
{
    printk(KERN_INFO "%s Ethernet Driver, V%s\n", CARDNAME, DRV_VERSION);

    return platform_driver_register(&keybus_driver);
}

static void __exit
keybus_cleanup(void)
{
    platform_driver_unregister(&keybus_driver);
}

module_init(keybus_init);
module_exit(keybus_cleanup);

MODULE_AUTHOR("Sascha Hauer, Ben Dooks");
MODULE_DESCRIPTION("Davicom keybus driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:keybus");
one more time~ one more chance~
级别: 侠客
UID: 7776
精华: 1
发帖: 73
金钱: 675 两
威望: 503 点
综合积分: 166 分
注册时间: 2009-07-28
最后登录: 2020-06-08
9楼  发表于: 2009-08-14 17:13
我猜是你要用的这个资源已经被别的驱动申请了~  但是申请已经被占用的资源会不会引起PANIC就不清楚了~

你在每条语句下面都加一条printk~ 看看是运行到哪条语句panic的~

引用第3楼kasim于2009-08-14 16:38发表的  :
就S3C2440A而言,不管是哪个Memory的bank,都不会出现S3C2410_CS3 + 3这种map,你在map什么?


= = 别说~  友善给的DM9000资源还真是这样写的~
  • «
  • 1
  • 2
  • 3
  • »
  • Pages: 1/3     Go