没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
23页
linux下的设备模型包括几个主要的概念sysfs (dev是用户空间接口,根据sysfs下的class目录由mdev负责建立)bus总线,linux下的设备都是建立在总线上的,platform总线是一个虚拟的总线,所有的的片上设备基本上都接在这个虚拟总线上device是设备device_driver是设备驱动class是类别,从功能角度对设备进行分类注意,在sys/bus目录下有platform目录和spi目录这两个目录下面的设备分别代表什么呢?
资源推荐
资源详情
资源评论
linux 2.6.36+ok6410 SPI 子系统接口讨论(在各位前辈总结的基础上进
行了进一步的整理)
下图是安装成功后, 目录下的主要结构,由于目录非常复杂仅仅列出了主要的结
构
sys 目录下 spi 子系统结构
接下来将从各 开始进行分析, 是构成内核对象的基础,函数是动态的构建和执
行的工具。所以梳理脉络就从结构开始。
下的设备模型包括几个主要的概念
( 是用户空间接口,根据 下的 目录由 负责建立)
总线, 下的设备都是建立在总线上的, 总线是一个虚拟的总线,所有的
的片上设备基本上都接在这个虚拟总线上
是设备
是设备驱动
是类别,从功能角度对设备进行分类
注意,在 目录下有 目录和 目录
这两个目录下面的设备分别代表什么呢?
下的设备有 和 分别对应了 上的 和
接口
一、 先说说 platform
platform.txt 是需要阅读的参考文档(linux-2.6.36.2-v1.05/Doc
umentation/driver-model/platform.txt)
子系统是 对不同的架构下设备的抽象归纳,即所有片上的设备都会
放在这个子目录下
我们先看一下 相关的
struct platform_device {
const char *name;
u32 id;
struct device dev;
u32 num_resources;
struct resource *resource;
};
从字面理解就是平台设备,注意它内含了一个名为 的 结构,
这有点像 的类继承的关系, 内核大量利用了这种类似继承的结构实现了 语言下
的面向对象编程。
后面谈到的 ! 的设备继承了 的结构。¬¬¬¬另外,还包含了一个 """
"结构的指针,注意和 的区别。也就是说资源是需要另外定义然后,将对象指针赋予这
里的结构指针。资源包含 !#$%$ 和 !&'。
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
void (*shutdown)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*suspend_late)(struct platform_device *, pm_message_t state);
int (*resume_early)(struct platform_device *);
int (*resume)(struct platform_device *);
struct device_driver driver;
};
结构就不多说了,主要是用来说明 驱动的结构。
下 面看 看 对象 实 例 s3c64xx-spi.0 的 定义 (linux-2.6.36.2-v1.05/
arch/arm/mach-s3c64xx/dev-spi.c)
static struct resource s3c64xx_spi0_resource[] = {
[0] = {
.start = S3C64XX_PA_SPI0,
.end = S3C64XX_PA_SPI0 + 0x100 - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = DMACH_SPI0_TX,
.end = DMACH_SPI0_TX,
.flags = IORESOURCE_DMA,
},
[2] = {
.start = DMACH_SPI0_RX,
.end = DMACH_SPI0_RX,
.flags = IORESOURCE_DMA,
},
[3] = {
.start = IRQ_SPI0,
.end = IRQ_SPI0,
.flags = IORESOURCE_IRQ,
},
};
static struct s3c64xx_spi_info s3c64xx_spi0_pdata = {
.cfg_gpio = s3c64xx_spi_cfg_gpio,
.fifo_lvl_mask = 0x7f,
.rx_lvl_offset = 13,
};
static u64 spi_dmamask = DMA_BIT_MASK(32);
struct platform_device s3c64xx_device_spi0 = {
.name = "s3c64xx-spi",
.id = 0,
.num_resources = ARRAY_SIZE(s3c64xx_spi0_resource),
.resource = s3c64xx_spi0_resource,
.dev = {
.dma_mask = &spi_dmamask,
.coherent_dma_mask = DMA_BIT_MASK(32),
.platform_data = &s3c64xx_spi0_pdata,
},
};
从上面的定义可以看出, 是 ( 的定义,系统根据这
个变量实现了 (,而它的类型是 ,也就是说这是一个平台设
备。( 就不说了同理。
下 面 是 驱 动 s3c64xx_spi_driver 的 定 义 , 系 统 根 据 这 个 定 义 实 现 了 平 台 驱 动
s3c64xx-spi(linux-2.6.36.2-v1.05/drivers/spi/spi_s3c64xx.c)
static struct platform_driver s3c64xx_spi_driver = {
.driver = {
.name = "s3c64xx-spi",
.owner = THIS_MODULE,
},
.remove = s3c64xx_spi_remove,
.suspend = s3c64xx_spi_suspend,
.resume = s3c64xx_spi_resume,
};
注意驱动的定义中含有很多的函数指针,这些函数是用来控制设备工作的标准动作。具
体功能这里就不解释了,各位看源码。
各位看到这里可能要问了那 ( 下的 ( 是在哪里实现的?它的类结构是什
么?
首先,我们得明白 ( 代表了 下的 接口,那么 ( 代表什么呢?
注意 ( 有两个数字,第一个 代表 接口,第 ) 个 呢?它代表这 总线上的片
外设备,这意味着一个 总线可以接多个片外设备,通过 进行片选。属于分时复用,
那么 ( 的定义在什么地方呢?首先,它和开发板的定义高度相关,也就是说它不会存
在于内核代码,也不会存在于芯片厂商三星公司提供的 系列代码中,那么它应该
在什么地方呢?答案是它应该在开发板的初始化代码中,即在友善之臂的 )((()
(*+++,( 中 , 很 遗 憾 友 善 之 臂 暂 时 没 有 支 持
, 的相关初始化代码需要我们自行定义,如何定义这里暂且不说,先说说这个设备
的类型定义在哪里?
下面就是片外设备的定义, 是片外设备需要的片选信号的定义,这
个片选信号的定义是必须的-
/* linux/arch/arm/plat-samsung/include/plat/s3c64xx-spi.h
*
* Copyright (C) 2009 Samsung Electronics Ltd.
* Jaswinder Singh <jassi.brar@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __S3C64XX_PLAT_SPI_H
#define __S3C64XX_PLAT_SPI_H
/**
* struct s3c64xx_spi_csinfo - ChipSelect description
* @fb_delay: Slave specific feedback delay.
* Refer to FB_CLK_SEL register definition in SPI chapter.
* @line: Custom 'identity' of the CS line.
* @set_level: CS line control.
*
* This is per SPI-Slave Chipselect information.
* Allocate and initialize one in machine init code and make the
* spi_board_info.controller_data point to it.
*/
struct s3c64xx_spi_csinfo {
u8 fb_delay;
unsigned line;
void (*set_level)(unsigned line_id, int lvl);
};
/**
* struct s3c64xx_spi_info - SPI Controller defining structure
* @src_clk_nr: Clock source index for the CLK_CFG[SPI_CLKSEL] field.
* @src_clk_name: Platform name of the corresponding clock.
* @num_cs: Number of CS this controller emulates.
* @cfg_gpio: Configure pins for this SPI controller.
* @fifo_lvl_mask: All tx fifo_lvl fields start at offset-6
* @rx_lvl_offset: Depends on tx fifo_lvl field and bus number
* @high_speed: If the controller supports HIGH_SPEED_EN bit
*/
struct s3c64xx_spi_info {
int src_clk_nr;
char *src_clk_name;
int num_cs;
int (*cfg_gpio)(struct platform_device *pdev);
/* Following two fields are for future compatibility */
int fifo_lvl_mask;
int rx_lvl_offset;
int high_speed;
};
/**
* s3c64xx_spi_set_info - SPI Controller configure callback by the board
* initialization code.
* @cntrlr: SPI controller number the configuration is for.
* @src_clk_nr: Clock the SPI controller is to use to generate SPI clocks.
* @num_cs: Number of elements in the 'cs' array.
*
* Call this from machine init code for each SPI Controller that
* has some chips attached to it.
*/
extern void s3c64xx_spi_set_info(int cntrlr, int src_clk_nr, int num_cs);
extern void s5pc100_spi_set_info(int cntrlr, int src_clk_nr, int num_cs);
extern void s5pv210_spi_set_info(int cntrlr, int src_clk_nr, int num_cs);
extern void s5p6440_spi_set_info(int cntrlr, int src_clk_nr, int num_cs);
extern void s5p6442_spi_set_info(int cntrlr, int src_clk_nr, int num_cs);
#endif /* __S3C64XX_PLAT_SPI_H */
剩余22页未读,继续阅读
资源评论
- 阳光非宅男2013-10-24非常好!!!就是后面讲的有点简单了。。
- qq266459822014-12-25文章是好文章~~可是博客上也有,咱这个需要的积分多了点吧~~还是谢谢了
- GoldenGraphics2014-03-05本人刚刚学习嵌入式,一开始就要搞SPI,毫无头绪~
- Rooooooooc2014-12-09很不错,对我有用!
不脱发的牧码人
- 粉丝: 42
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功