Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1255162
  • 博文数量: 404
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 5382
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-03 16:29
文章存档

2010年(40)

2009年(140)

2008年(224)

我的朋友

分类: LINUX

2008-12-23 12:46:03

浅析如何打印显示platform_bus_type总线上注册的所有设备信息

浅析如何打印显示platform_bus_type总线上注册的所有设备信息

#include <linux/platform_device.h>
typedef struct __luther_ss_fn {
    const char* name;
    int id;
    void** dev;
}_luther_ss_fn;
static int luther_gliethttp_get_platform_fn(struct device *dev, void *data)
{
    struct platform_device* platform_device = container_of(dev, struct platform_device, dev);
    _luther_ss_fn *luther_ss_fn = data;
    //enum {name_match = 0x01,id_match = 0x02};
    //int match = 0;
    printk(KERN_ALERT "%-20s %4d\n", platform_device->name, platform_device->id);
    if (luther_ss_fn->name)
    {
        if (strncmp(luther_ss_fn->name,platform_device->name, BUS_ID_SIZE))
            return 0;
    }
    
    if (luther_ss_fn->id == platform_device->id) {
        if (luther_ss_fn->dev) *luther_ss_fn->dev = platform_device;
    }
    
    return 0;
}
void* luther_gliethttp_get_platform_device_by_id_name(const char *name, int id, void **dev)
{
    _luther_ss_fn luther_ss_fn;

    luther_ss_fn.name = name;
    luther_ss_fn.id = id;
    luther_ss_fn.dev = dev;
    if (dev)
        *dev = NULL;

    bus_for_each_dev(&platform_bus_type, NULL, &luther_ss_fn, luther_gliethttp_get_platform_fn);

    if ( luther_ss_fn.dev && *luther_ss_fn.dev)
        return ((struct platform_device* )(*luther_ss_fn.dev))->dev.driver_data;
    else return NULL;
}

应用举例:
static int
wlan_init_module(void)
{
    ...
    void *pmmc_host;
    pmmc_host = luther_gliethttp_get_platform_device_by_id_name("pxa2xx-mci", 1, &pmmc_host);//用来获取mmc控制器的控制结构体
    mmc_detect_change(pmmc_host, 0);
//立即执行mmc检测,如果sd设备移出,那么/sys/bus/sdio/devices下的设备文件将从sysfs文件系统中删除,否则,添加设备文件[luther.gliethttp]
    ...
}

比如打印如下信息:
[  602.274382] pxa930-acipc           -1
[  602.278075] pxa3xx-freq             0
[  602.281889] pxa3xx-pmu              0
[  602.285551] pxa2xx-fb              -1
[  602.289641] micco-bl               -1
[  602.293303] micco-kp-bl            -1
[  602.297514] micco-ts               -1
[  602.301176] pxa3xx-imm             -1
[  602.305266] micco-charger          -1
[  602.308928] pxa-ispt               -1
[  602.313078] gpio-keys              -1
[  602.316740] pxa2xx-uart             0
[  602.320433] pxa2xx-uart             1
[  602.324126] pxa2xx-uart             2
[  602.327818] pxa3xx-keypad           0
[  602.331969] pxa-leds               -1
[  602.335631] gpio_sleep_debug       -1
[  602.339751] onenand                -1
[  602.343413] pxa9xx-u2o             -1
[  602.347563] pxa3xx-camera          -1
[  602.351225] a3212_hall             -1
[  602.355376] pxa2xx-mci              0
[  602.359068] pxa2xx-mci              1//获取该mmc host结构体
[  602.363249] cm3601_alsps           -1
[  602.366911] pxa2xx-i2c              0
[  602.371001] pxa2xx-i2s             -1
[  602.374663] pxa2xx-v4l2ov2         -1
[  602.378813] pxa3xx-rtc             -1
[  602.382506] pxa3xx-otg             -1
[  602.386168] pxa27x-ssp              0
[  602.389891] pxa27x-ssp              1
[  602.393553] pxa27x-ssp              2
[  602.397704] pxa27x-ssp              3
[  602.401366] ds1wm                  -1
[  602.405516] m2d                    -1
[  602.409209] pxa3xx-mved            -1
[  602.413359] bluetooth              -1
[  602.417021] alarm                  -1
[  602.421141] soc-audio              -1
[  602.424803] seh                     0
[  602.428954] msl                     0
[  602.432616] intel-ccidatastub       0
[  602.436766] marvell-ccinet          0

阅读(1057) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~