1. 程式人生 > >Linux裝置驅動--LCD平臺裝置與驅動(s3c64xx)

Linux裝置驅動--LCD平臺裝置與驅動(s3c64xx)

1 開發環境

    Host:Ubuntu14.04

    Target:s3c64xx

    Kernel:linux-3.18.2

2 平臺裝置

        關於裝置樹是如果被載入並解析成裝置節點的,詳見參考資料[1],本文重點分析如何利用裝置節點建立相依的平臺裝置。

2.1 platform_device建立&註冊

(1)裝置匹配表

const struct of_device_id of_default_bus_match_table[] = {
    { .compatible = "simple-bus", },
#ifdef CONFIG_ARM_AMBA
    { .compatible = "arm,amba-bus", },
#endif /* CONFIG_ARM_AMBA */
    {} /* Empty terminated list */
};
原始檔:drivers/of/platform.c

(2)入口定義

DT_MACHINE_START(S3C6400_DT, "Samsung S3C64xx (Flattened Device Tree)")
    /* Maintainer: Tomasz Figa <[email protected].com> */
    .dt_compat  = s3c64xx_dt_compat,
    .map_io     = s3c64xx_dt_map_io,
    .init_machine   = s3c64xx_dt_init_machine,
    .restart        = s3c64xx_dt_restart,                                                                                                                                                                    
MACHINE_END  

原始檔:arch/arm/mach-s3c64xx/mach-s3c64xx-dt.c

對比分析:與《Linux裝置驅動--LCD平臺裝置與驅動(smdk6410)》不同的是,這裡不再使用MACHINE_START,而是使用DT_MACHINE_START取代之[5]。

(3)s3c64xx入口函式

static void __init s3c64xx_dt_init_machine(void)
{
    samsung_wdt_reset_of_init();
    of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); /* 建立平臺裝置. */
}
原始檔:arch/arm/mach-s3c64xx/mach-s3c64xx-dt.c

    在s3c64xx入口函式中,呼叫of_platform_populate()函式根據裝置節點建立相應的平臺裝置。那麼of_platform_populate()具體是如何根據裝置節點建立相應的平臺裝置的呢?下文將對此進行詳細分析。

2.2 of_platform_populate()呼叫過程

(1)of_platform_populate()

    該函式主要根據裝置節點(device_node)建立相應的平臺裝置:

int of_platform_populate(struct device_node *root,
            const struct of_device_id *matches,
            const struct of_dev_auxdata *lookup,
            struct device *parent)
{
    struct device_node *child;
    int rc = 0;

    root = root ? of_node_get(root) : of_find_node_by_path("/");/* 獲取裝置樹. */
    if (!root)
        return -EINVAL;

    for_each_child_of_node(root, child) { /* 遍歷裝置樹. */
        rc = of_platform_bus_create(child, matches, lookup, parent, true); /* 建立平臺裝置. */
        if (rc)
            break;
    }   

    of_node_put(root);
    return rc; 
}
EXPORT_SYMBOL_GPL(of_platform_populate);

原始檔:drivers/of/platform.c

(2)of_platform_bus_create()

    該函式呼叫of_platform_device_create_pdata()函式建立平臺裝置(platform_device),如下第35行所示:

static int of_platform_bus_create(struct device_node *bus,
                  const struct of_device_id *matches,
                  const struct of_dev_auxdata *lookup,
                  struct device *parent, bool strict)
{
    const struct of_dev_auxdata *auxdata;
    struct device_node *child;
    struct platform_device *dev; /* 平臺裝置指標, 用於儲存新建立的平臺裝置. */
    const char *bus_id = NULL;
    void *platform_data = NULL;
    int rc = 0;

    /* Make sure it has a compatible property */
    if (strict && (!of_get_property(bus, "compatible", NULL))) {
        pr_debug("%s() - skipping %s, no compatible prop\n",
             __func__, bus->full_name);
        return 0;
    }

    auxdata = of_dev_lookup(lookup, bus);
    if (auxdata) {
        bus_id = auxdata->name;
        platform_data = auxdata->platform_data;
    }

    if (of_device_is_compatible(bus, "arm,primecell")) {
        /*
         * Don't return an error here to keep compatibility with older
         * device tree files.
         */
        of_amba_device_create(bus, bus_id, platform_data, parent);
        return 0;
    }
    /* 建立平臺裝置(platform_device) */
    dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent);
    if (!dev || !of_match_node(matches, bus)) /* 若建立失敗或不匹配, 則不再為子裝置節點建立平臺裝置. */
        return 0;

    for_each_child_of_node(bus, child) {
        pr_debug("   create child: %s\n", child->full_name);
        rc = of_platform_bus_create(child, matches, lookup, &dev->dev, strict); /* 遞迴, 為子裝置節點建立平臺裝置. */
        if (rc) {
            of_node_put(child);
            break;
        }
    }
    of_node_set_flag(bus, OF_POPULATED_BUS);
    return rc;
}

原始檔:drivers/of/platform.c

(3)of_platform_device_create_pdata()

    該函式呼叫of_device_add()將平臺設備註冊到系統中,如下第26行所示:

static struct platform_device *of_platform_device_create_pdata(
                    struct device_node *np,
                    const char *bus_id,
                    void *platform_data,
                    struct device *parent)
{
    struct platform_device *dev;

    if (!of_device_is_available(np) ||
        of_node_test_and_set_flag(np, OF_POPULATED))
        return NULL;

    dev = of_device_alloc(np, bus_id, parent);
    if (!dev)
        goto err_clear_flag;

    of_dma_configure(&dev->dev);
    dev->dev.bus = &platform_bus_type;
    dev->dev.platform_data = platform_data;

    /* We do not fill the DMA ops for platform devices by default.
     * This is currently the responsibility of the platform code
     * to do such, possibly using a device notifier
     */

    if (of_device_add(dev) != 0) {
        platform_device_put(dev);
        goto err_clear_flag;
    }

    return dev;

err_clear_flag:
    of_node_clear_flag(np, OF_POPULATED);
    return NULL;
}

原始檔:drivers/of/platform.c

(4)of_device_add()

    該函式呼叫device_add()函式將平臺設備註冊到系統中,如下第16行所示:

int of_device_add(struct platform_device *ofdev)
{
    BUG_ON(ofdev->dev.of_node == NULL);

    /* name and id have to be set so that the platform bus doesn't get
     * confused on matching */
    ofdev->name = dev_name(&ofdev->dev);
    ofdev->id = -1; 

    /* device_add will assume that this device is on the same node as
     * the parent. If there is no parent defined, set the node
     * explicitly */
    if (!ofdev->dev.parent)
        set_dev_node(&ofdev->dev, of_node_to_nid(ofdev->dev.of_node));

    return device_add(&ofdev->dev);
}

原始檔:drivers/of/device.c

(5)device_add()

    該函式是普通的設備註冊函式,與裝置樹並沒有直接的關係。也即說,裝置樹的機制最後在這裡與傳統機制相結合。

int device_add(struct device *dev)
{
	struct device *parent = NULL;
	struct kobject *kobj;
	struct class_interface *class_intf;
	int error = -EINVAL;

	dev = get_device(dev);
	if (!dev)
		goto done;

	if (!dev->p) {
		error = device_private_init(dev);
		if (error)
			goto done;
	}

	/*
	 * for statically allocated devices, which should all be converted
	 * some day, we need to initialize the name. We prevent reading back
	 * the name, and force the use of dev_name()
	 */
	if (dev->init_name) {
		dev_set_name(dev, "%s", dev->init_name);
		dev->init_name = NULL;
	}

	/* subsystems can specify simple device enumeration */
	if (!dev_name(dev) && dev->bus && dev->bus->dev_name)
		dev_set_name(dev, "%s%u", dev->bus->dev_name, dev->id);

	if (!dev_name(dev)) {
		error = -EINVAL;
		goto name_error;
	}

	pr_debug("device: '%s': %s\n", dev_name(dev), __func__);

	parent = get_device(dev->parent);
	kobj = get_device_parent(dev, parent);
	if (kobj)
		dev->kobj.parent = kobj;

	/* use parent numa_node */
	if (parent)
		set_dev_node(dev, dev_to_node(parent));

	/* first, register with generic layer. */
	/* we require the name to be set before, and pass NULL */
	error = kobject_add(&dev->kobj, dev->kobj.parent, NULL);
	if (error)
		goto Error;

	/* notify platform of device entry */
	if (platform_notify)
		platform_notify(dev);

	error = device_create_file(dev, &dev_attr_uevent);
	if (error)
		goto attrError;

	if (MAJOR(dev->devt)) {
		error = device_create_file(dev, &dev_attr_dev);
		if (error)
			goto ueventattrError;

		error = device_create_sys_dev_entry(dev);
		if (error)
			goto devtattrError;

		devtmpfs_create_node(dev);
	}

	error = device_add_class_symlinks(dev);
	if (error)
		goto SymlinkError;
	error = device_add_attrs(dev);
	if (error)
		goto AttrsError;
	error = bus_add_device(dev);
	if (error)
		goto BusError;
	error = dpm_sysfs_add(dev);
	if (error)
		goto DPMError;
	device_pm_add(dev);

	/* Notify clients of device addition.  This call must come
	 * after dpm_sysfs_add() and before kobject_uevent().
	 */
	if (dev->bus)
		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
					     BUS_NOTIFY_ADD_DEVICE, dev);

	kobject_uevent(&dev->kobj, KOBJ_ADD);
	bus_probe_device(dev);
	if (parent)
		klist_add_tail(&dev->p->knode_parent,
			       &parent->p->klist_children);

	if (dev->class) {
		mutex_lock(&dev->class->p->mutex);
		/* tie the class to the device */
		klist_add_tail(&dev->knode_class,
			       &dev->class->p->klist_devices);

		/* notify any interfaces that the device is here */
		list_for_each_entry(class_intf,
				    &dev->class->p->interfaces, node)
			if (class_intf->add_dev)
				class_intf->add_dev(dev, class_intf);
		mutex_unlock(&dev->class->p->mutex);
	}
done:
	put_device(dev);
	return error;
 DPMError:
	bus_remove_device(dev);
 BusError:
	device_remove_attrs(dev);
 AttrsError:
	device_remove_class_symlinks(dev);
 SymlinkError:
	if (MAJOR(dev->devt))
		devtmpfs_delete_node(dev);
	if (MAJOR(dev->devt))
		device_remove_sys_dev_entry(dev);
 devtattrError:
	if (MAJOR(dev->devt))
		device_remove_file(dev, &dev_attr_dev);
 ueventattrError:
	device_remove_file(dev, &dev_attr_uevent);
 attrError:
	kobject_uevent(&dev->kobj, KOBJ_REMOVE);
	kobject_del(&dev->kobj);
 Error:
	cleanup_device_parent(dev);
	if (parent)
		put_device(parent);
name_error:
	kfree(dev->p);
	dev->p = NULL;
	goto done;
}
EXPORT_SYMBOL_GPL(device_add);

原始檔:drivers/base/core.c

3 平臺驅動

參考資料

相關推薦

Linux裝置驅動--LCD平臺裝置驅動tiny4412

1 環境與簡介     Host:Ubuntu14.04(64bit)     Target:Tiny4412     Kernel:linux-3.5.0 2 平臺裝置 2.1 宣告 extern struct platform_device s5p_device_fim

Linux裝置驅動--LCD平臺裝置驅動smdk2440

1 環境與簡介     Host:Ubuntu14.04(64bit)     Target:smdk2440     Kernel:linux-2.6.39.4     類似於《Linux裝置驅動--WDT平臺裝置與驅動》,本文再以LCD為例進行說明。本文的原始碼均來自L

Linux裝置驅動--LCD平臺裝置驅動s3c64xx

1 開發環境     Host:Ubuntu14.04     Target:s3c64xx     Kernel:linux-3.18.2 2 平臺裝置         關於裝置樹是如果被載入並解析成裝置節點的,詳見參考資料[1],本文重點分析如何利用裝置節點建立相

Linux裝置驅動--LCD平臺裝置驅動smdk6410

1 環境與簡介     Host:Ubuntu14.04(64bit)     Target:smdk6410     Kernel:linux-3.5.0     在《Linux裝置驅動--LCD平臺裝置與驅動(smdk2440)》中基於linux-2.6.39.4對LC

軟體測試中樁模組驅動模組的概念區別轉載,打樁

樁模組和驅動模組(以C語言為例):   很多人對樁模組和驅動模組的概念會搞不清楚,那麼下面來介紹這兩個概念:   模組結構例項圖:   假設現在專案組把任務分給了7個人,每個人負責實現一個模組。你負責的是B模組,你很優秀,第一個完成了編碼工作,現在需要開展單元測試工作,先分析結構圖:   1、由於

linux應用之vim的安裝配置centos

utf8 power scroll pbo gb2312 nco pla red vma 1.vim的安裝 #yum search vim //查看vim相關軟件信息 #yum install -y vim* //在線安裝vim 2.vim的配置 (1)~/.vimi

Linux下NFS伺服器的搭建配置

一、NFS服務簡介  NFS 就是 Network FileSystem 的縮寫,最早之前是由sun 這家公司所發展出來的。 它最大的功能就是可以透過網路,讓不同的機器、不同的作業系統、可以彼此分享個別的檔案 (share files)。所以,你也可以簡單的將他看做是一個檔案伺服器 (file server

Linux中的Redis的下載安裝附圖

一,Redis下載         1,下載地址:http://redis.io/download         2,進入Redis官網首頁下載最新版進行. 二,安裝redis (在root許可權下操

平臺程式設計開發:Java雲平臺服務商一覽

因為Java語言的跨平臺性和高度靈活性,成為目前雲端計算平臺的主流開發語言;所以,這裡重點討論一下Java 雲平臺的比較情況。尤其是討論X5Cloud雲平臺與現有幾個Java雲平臺的聯絡和區別:      * App Engine (http://code.google.com/appengine/)    

linux驅動-7-平臺裝置驅動

[toc] --- ## 前言 區分**裝置驅動模型**和**平臺裝置驅動模型**。 **裝置驅動模型** 可以理解為 **匯流排、裝置、驅動**。 **平臺裝置驅動模型** 就是那些 Linux 核心管理沒有物理匯流排(*即是不需要特殊時序控制的裝置*)(*也是Linux核心沒有自動建立相應驅動匯流

Linux總線、設備驅動》USB設備發現機制

buffer 嵌入 void smo b- 嵌入式系統 root 顯示 ice 說明:本分析基於mstar801平臺Linux2.6.35.11內核,其他內核版本僅供參考。 一、程序在內核中的位置 1.usb host做為pci總線下的一個設備存在(嵌入式系統中有可能也會

Linux驅動平臺設備驅動模型簡析驅動分離分層概念的建立

技術 描述 rst 操作 mem iou 系統 簡單 reg Linux設備模型的目的:為內核建立一個統一的設備模型,從而有一個對系統結構的一般性抽象描述。換句話說,Linux設備模型提取了設備操作的共同屬性,進行抽象,並將這部分共同的屬性在內核中實現,而為需要新添加設備

Linux驅動學習筆記----------IIC框架流程

歷時一個月期末課程設計終於結束了!發現好多東西忘記了,iic流程也有些淡忘,有點慌,夜深人靜的時候就整理下吧!還有,杭州最近熱的我腦袋都不好用了! 關於iic: 1.是一種資料傳輸協議(spi,usb,sdio,uart…)

linux驅動篇之 driver_register 過程分析

linux驅動註冊過程分析--driver_register(一) 個人筆記,歡迎轉載,請註明出處,共同分享 共同進步  http://blog.csdn.net/richard_liujh/article/details/45825333 kernel版本3.10.1

Linux 驅動開發之核心模組開發 —— 核心模組編譯 Makefile 入門

一、模組的編譯  我們在前面核心編譯中驅動移植那塊,講到驅動編譯分為靜態編譯和動態編譯;靜態編譯即為將驅動直接編譯進核心,動態編譯即為將驅動編譯成模組。 而動態編譯又分為兩種: a -- 內部編譯        在核心原始碼目錄內編譯 b -- 外部編譯        在核

【翻譯】SklearnTensorFlow機器學習實用指南 ——第12章 裝置和伺服器上的分散式TensorFlow

在第 11 章,我們討論了幾種可以明顯加速訓練的技術:更好的權重初始化,批量標準化,複雜的優化器等等。 但是,即使採用了所有這些技術,在具有單個 CPU 的單臺機器上訓練大型神經網路可能需要幾天甚至幾周的時間。在本章中,我們將看到如何使用 TensorFlow 在多個裝置(C

LINUX系統服務管理Services---------第六天

rsync同步? ? ?虛擬機A? ? 1. 將防火墻狀態設置為trusted? 2.SELinux當前修改為permissive? 3.SELinux永久狀態修改為permissive? ? 4.清空Yum緩存,檢查Yum是否可用? ? 虛擬機B? ? 1. 將防火墻狀態設置為trusted? 2.SELi

LINUX系統服務管理Services---------第二天

根下常用的命令用途 自定義yum倉庫 ln創建軟連接 源碼包編譯安裝 主要用途/boot ? ? ? ? 存放系統引導必需的文件,包括內核、啟動配置/bin、/sbin ? 存放各種命令程序/dev ? ? ? ? ?存放硬盤、鍵盤、鼠標、光驅等各種設備文件/etc ? ? ? ? ?存放Li

LINUX系統服務管理Services---------第四天

dns服務器虛擬機A? ? 1. 將防火墻狀態設置為trusted? 2.SELinux當前修改為permissive? 3.SELinux永久狀態修改為permissive? ? 4.清空Yum緩存,檢查Yum是否可用? ? 虛擬機B? ? 1. 將防火墻狀態設置為trusted? 2.SELinux當前修

LINUX系統服務管理Services---------第五天

部署dhcp服務器 pxe網絡裝機服務器 虛擬機A? ? 1. 將防火墻狀態設置為trusted? 2.SELinux當前修改為permissive? 3.SELinux永久狀態修改為permissive? ? 4.清空Yum緩存,檢查Yum是否可用? ? 虛擬機B? ? 1. 將防火墻狀態設置為tr