sd/mmc驱动框架-(三)mmc子系统的数据结构

2023-12-28 10:08

本文主要是介绍sd/mmc驱动框架-(三)mmc子系统的数据结构,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

知识脉络框图:

 

一、host相关

1、struct mmc_host

struct mmc_host是mmc core由host controller抽象出来的结构体,用于代表一个mmc host控制器。 
* 数据结构如下:

struct mmc_host {struct device       *parent;   // 对应的host controller的devicestruct device       class_dev;   // mmc_host的device结构体,会挂在class/mmc_host下int         index;   // 该host的索引号const struct mmc_host_ops *ops; // 该host的操作集,由host controller设置,后面说明unsigned int        f_min;   // 该host支持的最低频率unsigned int        f_max;   // 该host支持的最大频率unsigned int        f_init;   // 该host使用的初始化频率/// 以下是和clock相关的成员int         clk_requests;   /* internal reference counter */unsigned int        clk_delay;  /* number of MCI clk hold cycles */bool            clk_gated;  /* clock gated */struct delayed_work clk_gate_work; /* delayed clock gate */unsigned int        clk_old;    /* old clock value cache */spinlock_t      clk_lock;   /* lock for clk fields */struct mutex        clk_gate_mutex; /* mutex for clock gating */struct device_attribute clkgate_delay_attr;unsigned long           clkgate_delay;/* host specific block data */   // 被主控制器驱动的mmc块设备数据和块相关的成员unsigned int        max_seg_size;   /* see blk_queue_max_segment_size */unsigned short      max_segs;   /* see blk_queue_max_segments */unsigned short      unused;unsigned int        max_req_size;   /* maximum number of bytes in one req */unsigned int        max_blk_size;   /* maximum size of one mmc block */unsigned int        max_blk_count;  /* maximum number of blocks in one req */unsigned int        max_discard_to; /* max. discard timeout in ms *//* private data 私有数据*/spinlock_t      lock;       /* lock for claim and bus ops */   // host的bus使用的锁struct mmc_ios      ios;        /* current io bus settings */   // io setting,后续说明u32         ocr;        /* the current OCR setting */   // 当前使用的ocr的值/* group bitfields together to minimize padding */unsigned int        use_spi_crc:1;unsigned int        claimed:1;  /* host exclusively claimed */   // host是否已经被占用unsigned int        bus_dead:1; /* bus has been released */   // host的bus是否处于激活状态int         rescan_disable; /* disable card detection */   // 禁止rescan的标识,禁止搜索cardint         rescan_entered; /* used with nonremovable devices */   // 是否已经rescan过的标识,对应不可移除的设备只能rescan一次struct mmc_card     *card;      /* device attached to this host */   // 和该host绑定在一起的cardwait_queue_head_t   wq;struct task_struct  *claimer;   /* task that has host claimed */   // 该host的占有者进程struct task_struct  *suspend_task;int         claim_cnt;  /* "claim" nesting count */   // 占有者进程对该host的占用计数struct delayed_work detect;   // 检测卡槽变化的工作struct wake_lock    detect_wake_lock;   // 检测卡槽变化的工作使用的锁const char      *wlock_name;   // 锁名称int         detect_change;  /* card detect flag */ // 需要检测卡槽变化的标识struct mmc_slot     slot;   // 卡槽的结构体const struct mmc_bus_ops *bus_ops;  /* current bus driver */   // host的mmc总线的操作集,后面说明unsigned int        bus_refs;   /* reference counter */   // host的mmc总线的使用计数unsigned int        bus_resume_flags;   // host的mmc总线的resume标识mmc_pm_flag_t       pm_flags;   /* requested pm features */#ifdef CONFIG_REGULATORbool            regulator_enabled; /* regulator state */   // 代表regulator(LDO)的状态
#endifstruct mmc_supply   supply;struct dentry       *debugfs_root;   // 对应的debug目录结构体struct mmc_async_req    *areq;      /* active async req */   // 当前正在处理的异步请求struct mmc_context_info context_info;   /* async synchronization info */ // 异步请求的信息unsigned int        actual_clock;   /* Actual HC clock rate */ // 实际的时钟频率
};
  • ocr值各个位代表的电压意义如下:
#define MMC_VDD_165_195     0x00000080  /* VDD voltage 1.65 - 1.95 */
#define MMC_VDD_20_21       0x00000100  /* VDD voltage 2.0 ~ 2.1 */
#define MMC_VDD_21_22       0x00000200  /* VDD voltage 2.1 ~ 2.2 */
#define MMC_VDD_22_23       0x00000400  /* VDD voltage 2.2 ~ 2.3 */
#define MMC_VDD_23_24       0x00000800  /* VDD voltage 2.3 ~ 2.4 */
#define MMC_VDD_24_25       0x00001000  /* VDD voltage 2.4 ~ 2.5 */
#define MMC_VDD_25_26       0x00002000  /* VDD voltage 2.5 ~ 2.6 */
#define MMC_VDD_26_27       0x00004000  /* VDD voltage 2.6 ~ 2.7 */
#define MMC_VDD_27_28       0x00008000  /* VDD voltage 2.7 ~ 2.8 */
#define MMC_VDD_28_29       0x00010000  /* VDD voltage 2.8 ~ 2.9 */
#define MMC_VDD_29_30       0x00020000  /* VDD voltage 2.9 ~ 3.0 */
#define MMC_VDD_30_31       0x00040000  /* VDD voltage 3.0 ~ 3.1 */
#define MMC_VDD_31_32       0x00080000  /* VDD voltage 3.1 ~ 3.2 */
#define MMC_VDD_32_33       0x00100000  /* VDD voltage 3.2 ~ 3.3 */
#define MMC_VDD_33_34       0x00200000  /* VDD voltage 3.3 ~ 3.4 */
#define MMC_VDD_34_35       0x00400000  /* VDD voltage 3.4 ~ 3.5 */
#define MMC_VDD_35_36       0x00800000  /* VDD voltage 3.5 ~ 3.6 */
  • host属性(mmc_host->caps)caps1支持的属性如下
#define MMC_CAP_4_BIT_DATA  (1 << 0)    /* Can the host do 4 bit transfers */
#define MMC_CAP_MMC_HIGHSPEED   (1 << 1)    /* Can do MMC high-speed timing */
#define MMC_CAP_SD_HIGHSPEED    (1 << 2)    /* Can do SD high-speed timing */
#define MMC_CAP_SDIO_IRQ    (1 << 3)    /* Can signal pending SDIO IRQs */
#define MMC_CAP_SPI     (1 << 4)    /* Talks only SPI protocols */
#define MMC_CAP_NEEDS_POLL  (1 << 5)    /* Needs polling for card-detection */
#define MMC_CAP_8_BIT_DATA  (1 << 6)    /* Can the host do 8 bit transfers */#define MMC_CAP_NONREMOVABLE    (1 << 8)    /* Nonremovable e.g. eMMC */
#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9)    /* Waits while card is busy */
#define MMC_CAP_ERASE       (1 << 10)   /* Allow erase/trim commands */
#define MMC_CAP_1_8V_DDR    (1 << 11)   /* can support *//* DDR mode at 1.8V */
#define MMC_CAP_1_2V_DDR    (1 << 12)   /* can support *//* DDR mode at 1.2V */
#define MMC_CAP_POWER_OFF_CARD  (1 << 13)   /* Can power off after boot */
#define MMC_CAP_BUS_WIDTH_TEST  (1 << 14)   /* CMD14/CMD19 bus width ok */
#define MMC_CAP_UHS_SDR12   (1 << 15)   /* Host supports UHS SDR12 mode */
#define MMC_CAP_UHS_SDR25   (1 << 16)   /* Host supports UHS SDR25 mode */
#define MMC_CAP_UHS_SDR50   (1 << 17)   /* Host supports UHS SDR50 mode */
#define MMC_CAP_UHS_SDR104  (1 << 18)   /* Host supports UHS SDR104 mode */
#define MMC_CAP_UHS_DDR50   (1 << 19)   /* Host supports UHS DDR50 mode */
#define MMC_CAP_DRIVER_TYPE_A   (1 << 23)   /* Host supports Driver Type A */
#define MMC_CAP_DRIVER_TYPE_C   (1 << 24)   /* Host supports Driver Type C */
#define MMC_CAP_DRIVER_TYPE_D   (1 << 25)   /* Host supports Driver Type D */
#define MMC_CAP_CMD23       (1 << 30)   /* CMD23 supported. */
#define MMC_CAP_HW_RESET    (1 << 31)   /* Hardware reset */

2、struct mmc_host_ops
mmc core将host需要提供的一些操作方法封装成struct mmc_host_ops。 
mmc core主模块的很多接口都是基于这里面的操作方法来实现的,通过这些方法来操作host硬件达到对应的目的。 
所以struct mmc_host_ops也是host controller driver需要实现的核心部分。

struct mmc_host_ops {/** 'enable' is called when the host is claimed and 'disable' is called* when the host is released. 'enable' and 'disable' are deprecated.*/int (*enable)(struct mmc_host *host);   // 使能host,当host被占用时(第一次调用mmc_claim_host)调用int (*disable)(struct mmc_host *host);   // 禁用host,当host被释放时(第一次调用mmc_release_host)调用/** It is optional for the host to implement pre_req and post_req in* order to support double buffering of requests (prepare one* request while another request is active).* pre_req() must always be followed by a post_req().* To undo a call made to pre_req(), call post_req() with* a nonzero err condition.*/// post_req和pre_req是为了实现异步请求处理而设置的// 异步请求处理就是指,当另外一个异步请求还没有处理完成的时候,可以先准备另外一个异步请求而不必等待// 具体参考《mmc core主模块》void    (*post_req)(struct mmc_host *host, struct mmc_request *req,int err);void    (*pre_req)(struct mmc_host *host, struct mmc_request *req,bool is_first_req);void    (*request)(struct mmc_host *host, struct mmc_request *req); // host处理mmc请求的方法,在mmc_start_request中会调用void    (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);   // 设置host的总线的io settingint (*get_ro)(struct mmc_host *host);   // 获取host上的card的读写属性int (*get_cd)(struct mmc_host *host);   // 检测host的卡槽中card的插入状态/* optional callback for HC quirks */void    (*init_card)(struct mmc_host *host, struct mmc_card *card);   // 初始化card的方法int (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);   // 切换信号电压的方法/* Check if the card is pulling dat[0:3] low */int (*card_busy)(struct mmc_host *host);   // 用于检测card是否处于busy状态/* The tuning command opcode value is different for SD and eMMC cards */int (*execute_tuning)(struct mmc_host *host, u32 opcode);   // 执行tuning操作,为card选择一个合适的采样点int (*select_drive_strength)(unsigned int max_dtr, int host_drv, int card_drv);   // 选择信号的驱动强度void    (*hw_reset)(struct mmc_host *host);   // 硬件复位void    (*card_event)(struct mmc_host *host);   // unsigned long (*get_max_frequency)(struct mmc_host *host); // 获取host支持的最大频率的方法unsigned long (*get_min_frequency)(struct mmc_host *host);   // 获取host支持的最小频率的方法int (*notify_load)(struct mmc_host *, enum mmc_load);int (*stop_request)(struct mmc_host *host);   // 停止请求处理的方法unsigned int    (*get_xfer_remain)(struct mmc_host *host);
};

 

3.s3c2440 host驱动中初始化hmmc_host结构体成员的实战代码分析:

/** Platform driver and initialization.*/
static void __init s3c2440mmc_host_init(struct s3c2440mmc_host *host, struct mmc_host *mmc)
{struct s3c2440mmc_platform_data *pdata = host->pdata;mmc->ops = &s3c2440mmc_ops;//主控制器操作函数集合mmc->f_min = 200000;//控制器的最小时钟频率mmc->f_max = pdata->max_freq;//控制器的最大时钟频率mmc->ocr_avail = pdata->ocr_avail;//控制器的供电范围mmc->caps |= pdata->capacity;//控制器的支持的特殊功能mmc->pm_flags |= pdata->pm_flags;
#ifdef CONFIG_MMC_BLOCK_BOUNCEmmc->max_blk_count = 65535;//mmc块设备的最大块数mmc->max_req_size = PAGE_SIZE * 16;//单个请求的最大数据长度,以字节为单位
#elsemmc->max_segs = MAX_SEGS;//mmc->max_blk_count = 4096;//单个请求的最大块数mmc->max_req_size = 4096 * 512; //单个请求的最大数据长度,以字节为单位
#endifmmc->max_blk_size = 512; //mmc块设备的最大块大小mmc->max_seg_size = mmc->max_req_size;//物理段的最大长度,以字节为单位host->mmc = mmc; setup_timer(&host->request_timer, s3c2440mmc_request_timeout,(unsigned long)host);mmc_add_host(mmc);//添加mmc host
}

 

 

 

 

参考文献:

1.《深入实践嵌入Linux系统移植 范展源 刘韬》

2. https://blog.csdn.net/ooonebook/article/details/55105481

这篇关于sd/mmc驱动框架-(三)mmc子系统的数据结构的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/545595

相关文章

C++ HTTP框架推荐(特点及优势)

《C++HTTP框架推荐(特点及优势)》:本文主要介绍C++HTTP框架推荐的相关资料,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. Crow2. Drogon3. Pistache4. cpp-httplib5. Beast (Boos

SpringBoot基础框架详解

《SpringBoot基础框架详解》SpringBoot开发目的是为了简化Spring应用的创建、运行、调试和部署等,使用SpringBoot可以不用或者只需要很少的Spring配置就可以让企业项目快... 目录SpringBoot基础 – 框架介绍1.SpringBoot介绍1.1 概述1.2 核心功能2

如何在Ubuntu上安装NVIDIA显卡驱动? Ubuntu安装英伟达显卡驱动教程

《如何在Ubuntu上安装NVIDIA显卡驱动?Ubuntu安装英伟达显卡驱动教程》Windows系统不同,Linux系统通常不会自动安装专有显卡驱动,今天我们就来看看Ubuntu系统安装英伟达显卡... 对于使用NVIDIA显卡的Ubuntu用户来说,正确安装显卡驱动是获得最佳图形性能的关键。与Windo

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

嵌入式Linux之使用设备树驱动GPIO的实现方式

《嵌入式Linux之使用设备树驱动GPIO的实现方式》:本文主要介绍嵌入式Linux之使用设备树驱动GPIO的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、设备树配置1.1 添加 pinctrl 节点1.2 添加 LED 设备节点二、编写驱动程序2.1

嵌入式Linux驱动中的异步通知机制详解

《嵌入式Linux驱动中的异步通知机制详解》:本文主要介绍嵌入式Linux驱动中的异步通知机制,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、异步通知的核心概念1. 什么是异步通知2. 异步通知的关键组件二、异步通知的实现原理三、代码示例分析1. 设备结构

usb接口驱动异常问题常用解决方案

《usb接口驱动异常问题常用解决方案》当遇到USB接口驱动异常时,可以通过多种方法来解决,其中主要就包括重装USB控制器、禁用USB选择性暂停设置、更新或安装新的主板驱动等... usb接口驱动异常怎么办,USB接口驱动异常是常见问题,通常由驱动损坏、系统更新冲突、硬件故障或电源管理设置导致。以下是常用解决

C#数据结构之字符串(string)详解

《C#数据结构之字符串(string)详解》:本文主要介绍C#数据结构之字符串(string),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录转义字符序列字符串的创建字符串的声明null字符串与空字符串重复单字符字符串的构造字符串的属性和常用方法属性常用方法总结摘

Python Dash框架在数据可视化仪表板中的应用与实践记录

《PythonDash框架在数据可视化仪表板中的应用与实践记录》Python的PlotlyDash库提供了一种简便且强大的方式来构建和展示互动式数据仪表板,本篇文章将深入探讨如何使用Dash设计一... 目录python Dash框架在数据可视化仪表板中的应用与实践1. 什么是Plotly Dash?1.1

基于Flask框架添加多个AI模型的API并进行交互

《基于Flask框架添加多个AI模型的API并进行交互》:本文主要介绍如何基于Flask框架开发AI模型API管理系统,允许用户添加、删除不同AI模型的API密钥,感兴趣的可以了解下... 目录1. 概述2. 后端代码说明2.1 依赖库导入2.2 应用初始化2.3 API 存储字典2.4 路由函数2.5 应