日期:2014-05-16  浏览次数:20723 次

platform很奇怪的问题!求高手围观!!!急。。。。。。。。。。。
定义一个平台设备的时候,把代码和资源加入平台文件,系统应该就会帮我们注册吧!但是我看到内核中的RTC驱动,它在probe中又注册了一个设备!这不是重复了吗?为什么呢!求高手解救!!!!probe代码如下:
ds1511_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
struct resource *res;
struct rtc_plat_data *pdata = NULL;
int ret = 0;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
return -ENODEV;
}
pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
if (!pdata) {
return -ENOMEM;
}
pdata->size = res->end - res->start + 1;
if (!request_mem_region(res->start, pdata->size, pdev->name)) {
ret = -EBUSY;
goto out;
}
pdata->baseaddr = res->start;
pdata->size = pdata->size;
ds1511_base = ioremap(pdata->baseaddr, pdata->size);
if (!ds1511_base) {
ret = -ENOMEM;
goto out;
}
pdata->ioaddr = ds1511_base;
pdata->irq = platform_get_irq(pdev, 0);

/*
* turn on the clock and the crystal, etc.
*/
rtc_write(0, RTC_CMD);
rtc_write(0, RTC_CMD1);
/*
* clear the wdog counter
*/
rtc_write(0, DS1511_WD_MSEC);
rtc_write(0, DS1511_WD_SEC);
/*
* start the clock
*/
rtc_enable_update();

/*
* check for a dying bat-tree
*/
if (rtc_read(RTC_CMD1) & DS1511_BLF1) {
dev_warn(&pdev->dev, "voltage-low detected.\n");
}

/*
* if the platform has an interrupt in mind for this device,
* then by all means, set it
*/
if (pdata->irq > 0) {
rtc_read(RTC_CMD1);
if (request_irq(pdata->irq, ds1511_interrupt,
IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) {

dev_warn(&pdev->dev, "interrupt not available.\n");
pdata->irq = 0;
}
}

rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops,
THIS_MODULE); if (IS_ERR(rtc)) {
ret = PTR_ERR(rtc);
goto out;
}
pdata->rtc = rtc;
platform_set_drvdata(pdev, pdata);
ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
if (ret) {
goto out;
}
return 0;
 out:
if (pdata->rtc) {
rtc_device_unregister(pdata->rtc);
}
if (pdata->irq > 0) {
free_irq(pdata->irq, pdev);
}
if (ds1511_base) {
iounmap(ds1511_base);
ds1511_base = NULL;
}
if (pdata->baseaddr) {
release_mem_region(pdata->baseaddr, pdata->size);
}

kfree(pdata);
return ret;
}

 

------解决方案--------------------
虚拟总线的探测过程,实在不配称为设备探测。因为需要程序员手动注册device和设备上的资源

pci总线和usb总线有真实的物理的探测设备的能力,不需要程序员手动注册设备
要再具体,就只有去读pci和usb的标准