码迷,mamicode.com
首页 > 系统相关 > 详细

Linux MMC framework2-host driver简介

时间:2017-04-17 13:24:54      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:remove   需要   todo   驱动   线程   mic   超时   互斥   border   

声明:本文很多内容和思路参考了http://www.wowotech.net/comm/mmc_host_driver.html,对原作者表示感谢!

1.前言

本文是Linux MMC framework的第二篇,将从驱动工程师的角度,介绍MMC host controller driver有关的知识,学习并掌握如何在MMC framework的框架下,编写MMC控制器的驱动程序。同时,通过本篇文章,我们会进一步的理解MMC、SD、SDIO等有关的基础知识。

2.主要数据结构和API

 2.1 struct mmc_host

 

Elemete Name struct mmc_host
Path include/linux/mmc/host.h
Responsiblities

mmc core使用struct mmc_host来抽象mmc host controller

Attributions
  • parent : struct device *类型,指向该mmc host的父设备,一般为注册此mmc_host的platform device
  • class_dev:一个struct device类型的变量,是该MMC host在设备模型中作为一个“设备”的体现。当然,人如其名,该设备从属于某一个class(mmc_host_class)
  • index:该mmc_host的索引号,因为有可能有多个mmc host controller
  • ops:struct mmc_host_ops *类型的指针,包含了此mmc_host所有的操作函数集,见struct mmc_host_ops结构体描述
  • f_min、f_max、f_init,该MMC host支持的时钟频率范围,最小频率、最大频率以及初始频率
  • ocr_avail:通常的OCR电压范围
  • ocr_avail_sdio、ocr_avail_sd、ocr_avail_mmc:sdio sd mmc特定的电压范围
  • pm_notify:struct notifier_block类型,电源管理相关的notify
  • max_current_330/max_current_300/max_current_180:支持的最大电流
  • mmcid:
  • caps:host所具备的能力
  • caps2:host所具备的其它功能
  • pm_caps:mmc_pm_flag_t类型,支持的pm特性
  •  
  • clk_requests:
  • clk_delay:
  • clk_gated:clk是否已经开启了
  • clk_gate_work:struct delayed_work类型
  • clk_old:
  • clk_lock:spinlock_t 类型,对clk相关临界资源保护
  • clk_gate_mutex:struct mutex,保护clk gate的排它锁
  • clkgate_delay_attr:struct device_attribute类型
  • clkgate_delay:
  •  
  • max_seg_size:一个segment最大为多少字节
  • max_segs:最多支持多少segments
  • unused:
  • max_req_size:一个request的最大字节个数
  • max_blk_size:一个mmc block的最大大小
  • max_blk_count:一个request的最大block数目
  • max_discard_to:最大的discard超时时间(ms)
  •  
  • lock:spinlock_t类型mmc的互斥保护
  • ios:struct mmc_ios类型,当前的io总线设置
  • ocr:当前的操作电压设置
  •  
  • use_spi_crc:
  • claimed:host排他声明
  • bus_dead:总线是否被释放
  • removed:host是否被移除了
  • rescan_disable:是否禁用卡检测,一般初始时禁用,ready后才使能
  • rescan_entered:用于非可移除式设备
  • card:struct mmc_card *类型,用于连接到这个host的设备
  • wq:wait_queue_head_t类型,work队列
  • claimer:struct task_struct *类型,host声明的task
  • claim_cnt:"claim" nesting count
  • detect:struct delayed_work 类型,用于检测卡的work线程
  • detect_wake_lock:struct wake_lock 
  • detect_change:card detect flag 
  • slot:struct mmc_slot类型;
  • bus_ops:struct mmc_bus_ops *类型, current bus driver 
  • bus_refs:reference counter
  • bus_resume_flags:
  • sdio_irqs:
  • sdio_irq_thread:struct task_struct *类型
  • sdio_irq_pending:
  • sdio_irq_thread_abort:atomic_t类型
  • pm_flags:mmc_pm_flag_t 类型,请求的pm特性
  • led:struct led_trigger *类型
  • regulator_enabled:regulator状态
  • supply:struct mmc_supply类型
  • debugfs_root:struct dentry *类型,用于在debugfs中显示相应节点
  • areq:struct mmc_async_req *类型,  /* active async req */
  • context_info:struct mmc_context_info类型,; /* async synchronization info */
  • fail_mmc_request:struct fault_attr类型
  • actual_clock:Actual HC clock rate
  • slotno:used for sdio acpi binding
  • private:一个0长度的数组,可以在mmc_alloc_host时指定长度,由host controller driver自行支配
Operations
  • struct mmc_host *mmc_alloc_host(int extra, struct device *dev)

分配一个mmc_host结构体,并对其进行初始化

  • int mmc_add_host(struct mmc_host *host)

将host device注册进设备驱动模型,并做host硬件的初始化,向PM core 注册notify, 在本函数完成之前,必须能保证host可以使用

  • void mmc_remove_host(struct mmc_host *host)

将host device从设备驱动模型移除,并将所有的卡与bus切断连接,向pm core注销notify,将mmc bus掉电

2.2 struct mmc_host_ops

Elemete Name struct mmc_host_ops
Path include/linux/mmc/host.h
Responsiblities

主要包含了host contrller 所需要实现的操作

Attributions
  • post_req/pre_req:是为了支持双buffer的请求(一个请求正在处理,同时准备另一个请求)
  • request:用来处理一次transfer request

 

如下的函数可能会sleep,不能在中断上下文中调用:

  • set_ios:
  • get_ro:获取卡的读写状态,返回0表示可读写卡,返回1表示只读卡,返回-ENOSYS表示不支持,返回其它的负值表示其它错误发生
  • get_cd:返回0表示卡未连接,返回1表示卡有连接,返回-ENOSYS表示不支持,返回其它的负值表示其它错误发生
  • enable_sdio_irq:

 

  • init_card:
  • start_signal_voltage_switch:
  • card_busy:
  • execute_tuning:根据SD和eMMC卡的不同,调节tuning命令操作码值

 

  • select_drive_strength:设定驱动能力
  • hw_reset:对device执行reset操作
  • card_event:

 

  • multi_io_quirk
Operations

 

 

TODO

Linux MMC framework2-host driver简介

标签:remove   需要   todo   驱动   线程   mic   超时   互斥   border   

原文地址:http://www.cnblogs.com/smartjourneys/p/6716054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!