首页 > 系统相关 >linux驱动编写(dma驱动)

linux驱动编写(dma驱动)

时间:2022-11-23 23:32:21浏览次数:34  
标签:dma s3c24xx slave linux device 驱动 s3cdma memcpy




    linux下面的驱动虽然什么样的情形都有,但是dma驱动却并不少见。dma可以有很多的好处,其中最重要的功能就是能够帮助我们将数据搬来搬去,这个时候cpu就由时间去做别的事情了,提高了设备效率。


1、dma驱动在什么地方

drivers/dma


2、如何看s3c的dma驱动,先看Kconfig

config S3C24XX_DMAC
bool "Samsung S3C24XX DMA support"
depends on ARCH_S3C24XX || COMPILE_TEST
select DMA_ENGINE
select DMA_VIRTUAL_CHANNELS
help
Support for the Samsung S3C24XX DMA controller driver. The
DMA controller is having multiple DMA channels which can be
configured for different peripherals like audio, UART, SPI.
The DMA controller can transfer data from memory to peripheral,
periphal to memory, periphal to periphal and memory to memory.


3、发现s3c只依赖于S3C24XX_DMAC,这样可以接着看Makefile

obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o


4、确认驱动文件为s3c24xx-dma.c,了解基本结构

static struct platform_driver s3c24xx_dma_driver = {
.driver = {
.name = "s3c24xx-dma",
},
.id_table = s3c24xx_dma_driver_ids,
.probe = s3c24xx_dma_probe,
.remove = s3c24xx_dma_remove,
};

module_platform_driver(s3c24xx_dma_driver);


5、驱动为基本的platform driver,接着就可以了解probe函数了

/* Initialize memcpy engine */
dma_cap_set(DMA_MEMCPY, s3cdma->memcpy.cap_mask);
dma_cap_set(DMA_PRIVATE, s3cdma->memcpy.cap_mask);
s3cdma->memcpy.dev = &pdev->dev;
s3cdma->memcpy.device_free_chan_resources =
s3c24xx_dma_free_chan_resources;
s3cdma->memcpy.device_prep_dma_memcpy = s3c24xx_dma_prep_memcpy;
s3cdma->memcpy.device_tx_status = s3c24xx_dma_tx_status;
s3cdma->memcpy.device_issue_pending = s3c24xx_dma_issue_pending;
s3cdma->memcpy.device_config = s3c24xx_dma_set_runtime_config;
s3cdma->memcpy.device_terminate_all = s3c24xx_dma_terminate_all;
s3cdma->memcpy.device_synchronize = s3c24xx_dma_synchronize;

/* Initialize slave engine for SoC internal dedicated peripherals */
dma_cap_set(DMA_SLAVE, s3cdma->slave.cap_mask);
dma_cap_set(DMA_CYCLIC, s3cdma->slave.cap_mask);
dma_cap_set(DMA_PRIVATE, s3cdma->slave.cap_mask);
s3cdma->slave.dev = &pdev->dev;
s3cdma->slave.device_free_chan_resources =
s3c24xx_dma_free_chan_resources;
s3cdma->slave.device_tx_status = s3c24xx_dma_tx_status;
s3cdma->slave.device_issue_pending = s3c24xx_dma_issue_pending;
s3cdma->slave.device_prep_slave_sg = s3c24xx_dma_prep_slave_sg;
s3cdma->slave.device_prep_dma_cyclic = s3c24xx_dma_prep_dma_cyclic;
s3cdma->slave.device_config = s3c24xx_dma_set_runtime_config;
s3cdma->slave.device_terminate_all = s3c24xx_dma_terminate_all;
s3cdma->slave.device_synchronize = s3c24xx_dma_synchronize;
s3cdma->slave.filter.map = pdata->slave_map;
s3cdma->slave.filter.mapcnt = pdata->slavecnt;
s3cdma->slave.filter.fn = s3c24xx_dma_filter;


6、通过code获悉,s3cdma有master和slave两个engine,且部分接口共享。

只要完成dma接口的适配,dma就可以正常使用了。当然,前提是,两个engine要进行注册使用。

ret = dma_async_device_register(&s3cdma->memcpy);
if (ret) {
dev_warn(&pdev->dev,
"%s failed to register memcpy as an async device - %d\n",
__func__, ret);
goto err_memcpy_reg;
}

ret = dma_async_device_register(&s3cdma->slave);
if (ret) {
dev_warn(&pdev->dev,
"%s failed to register slave as an async device - %d\n",
__func__, ret);
goto err_slave_reg;
}


标签:dma,s3c24xx,slave,linux,device,驱动,s3cdma,memcpy
From: https://blog.51cto.com/feixiaoxing/5881993

相关文章

  • linux驱动编写(电源管理驱动)
      对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提高用户体验方面有很大的好处。所以,各个soc厂家在这方面花了很多的功夫。......
  • linux驱动编写(摄像头驱动)
       对于现代嵌入式设备,特别是手机来说,摄像头是很重要的一个设备。很多同学买手机,一看颜值,第二就看摄像头拍照如何。所以,从某个角度来说,摄像头是各个厂家主打的应用功能......
  • linux驱动编写(nand flash驱动)
      很长一段时间,nandflash都是嵌入式的标配产品。nandflash价格便宜,存储量大,适用于很多的场景。现在很普及的ssd,上面的存储模块其实也是由一块一块nandflash构成的。......
  • 在Ubuntu Linux上安装Deb文件的三种方法
    https://zhuanlan.zhihu.com/p/339632982?ivk_sa=1024320u方法一:在.deb文件夹下(应该是Downloads文件夹),双击.deb文件方法二:使用Gdebi应用程序来安装deb软件包及其依赖项......
  • 简述linux系统中软件包管理系统
    前几篇文章一一介绍了LINUX进程管理控制命令,详细介绍了静态查看ps命令和动态查看top命令,以及中断、停止命令在实际管理控制过程中的一些实践操作等这篇文章主要简单介绍下......
  • 使用ZLG7289,51单片机驱动的,显示按键号
    1;WritedbyLinXiwei,on2006.06.152;完成功能:等待按键输入,然后将所读到的按键码转换成十进制,送回ZLG显示,同时将前面的显示内容左移,并使当前按键值闪烁34......
  • 使用ZLG7289,51单片机驱动的带有按键功能的时钟小程序
    按键功能说明:KEY0:闪烁显示小时,并修改小时KEY1:闪烁显示分钟,并修改分钟KEY2:闪烁显示秒钟,并修改秒钟KEY12:确认修改,修改结束KEY13:上调时间KEY15:下调时间1......
  • 使用ZLG7289,51单片机驱动的时钟显示小程序
    1;*******ZLG7289PARAMETERS*******2ZLG_BIT_CNTEQU30H;Thenumberofdatasended;循环次数3ZLG_REC_BUFEQU31H;T......
  • AIR32F103(六) ADC,I2S,DMA和ADPCM实现录音播放功能
    目录AIR32F103(一)合宙AIR32F103CBT6开发板上手报告AIR32F103(二)Linux环境和LibOpenCM3项目模板AIR32F103(三)Linux环境基于标准外设库的项目模板AIR32F103(四)2......
  • linux命令风格与mysql启动
    Linux三种风格(Unix、BSD、GNU)下的ps的参数说明mysqld_safe是什么使用mysqld_safe启动mysql服务,mysqld_safe为mysqld的守护进程,在BSD风格的unix系统上,常用mysqld_safe脚......