设备树下的platform总线

of _iomap 函数

作用:of iomap函数用于直接内存映射,以前我们会通过ioremap函数来完成物理地址到虚拟地址的映射。
函数原型:

#include <linux/of_address.h>
void iomem *of_iomap(struct device_node *np,int index)

参数:

  • np:设备节点。
  • index: reg属性中要完成内存映射的段,如果reg属性只有一段的话index就设置0。返回值:经过内存映射后的虚拟内存首地址,如果为NULL 的话表示内存映射失败

代码 rk3399 为例

  • beep_driver.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/io.h>struct device_node *test_device_node;
u32 out_value[2] = {0};
unsigned int *vir_gpio_dr;struct of_device_id of_match_table[] = {{.compatible = "test1234"},{}};int misc_open(struct inode * inode, struct file * file){printk("hello misc_open \n");return 0;
}int misc_release(struct inode * inode, struct file * file){printk("hello misc_release bye bye \n");return 0;
}int misc_read(struct file* file, char __user * ubuf, size_t size, loff_t * loff_t){char kbuf[64] = "heheh_read";printk("hello misc_read \n");if(copy_to_user(ubuf, kbuf, strlen(kbuf)) != 0 ){printk("copy_to_user error \n");return -1;}return 0;}int misc_write(struct file * file, const char __user * ubuf, size_t size, loff_t * loff_t){char kbuf[64] = {0};printk("hello misc_write \n");if (copy_from_user(kbuf, ubuf, size) != 0){printk("copy_from_to_user error \n");return -1;}printk("kbuf is %s \n", kbuf);if (kbuf[0] == 1){*vir_gpio_dr = 0x4a400000;}else if (kbuf[0] == 0){*vir_gpio_dr = 0x4a000000;}return 0;}struct file_operations misc_fops =
{.owner = THIS_MODULE,.open = misc_open,.release = misc_release,.read = misc_read,.write = misc_write
};struct miscdevice misc_dev =
{.minor = MISC_DYNAMIC_MINOR,.name = "hello_misc",.fops = &misc_fops
};int beep_probe(struct platform_device *pdev){int ret = 0;printk("beep_probe \n");printk("node name is %s \n", pdev->dev.of_node->name);#if 0//使用这个获取device_node 节点test_device_node = of_find_node_by_path("/test");if (test_device_node == NULL){printk("of_find_node_by_path is error \n");return -1;}
#endiftest_device_node = pdev->dev.of_node;ret = of_property_read_u32_array(test_device_node, "reg", out_value, 2);if ( ret < 0){printk("of_property_read_u32_array is error \n");return -1;}printk("out_value[0] = 0x%08x \n", out_value[0]);printk("out_value[1] = 0x%08x \n", out_value[1]);vir_gpio_dr = of_iomap(test_device_node, 0);if(vir_gpio_dr == NULL){printk("of_iomap is error \n");return -1;}printk("of_iomap is success \n");// vir_gpio_dr = ioremap(out_value[1], 1);// if (vir_gpio_dr == NULL)// {//     printk("GPIO5_DR ioremap error \n");//     return -1;// }// printk("GPIO5_DR ioremap ok \n");ret = misc_register(&misc_dev);if (ret <0){printk("misc_registe is error \n");}return 0;
}int beep_remove(struct platform_device *pdev){printk("beep_remove \n");return 0;
}const struct platform_device_id  beep_id_table = {.name = "beep_test"
};struct platform_driver beep_device =
{.probe = beep_probe,.remove = beep_remove,.driver = {.name = "123",.owner = THIS_MODULE,.of_match_table = of_match_table},.id_table = &beep_id_table
};static int beep_driver_init(void){int ret = 0;printk(KERN_EMERG "hello world enter \n");ret = platform_driver_register(&beep_device);if (ret < 0){printk("platform_driver_register 失败\n");}printk("platform_driver_register ok\n");return 0;
}static void beep_driver_exit(void){printk(KERN_EMERG "hello world exit! \n");platform_driver_unregister(&beep_device);
}module_init(beep_driver_init);
module_exit(beep_driver_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("LIYU");
  • app.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>int main(int argc, char const *argv[]){int fd;char buf[64] = {0};char buf_write[64] = "write aaaaaaaaa";fd = open("/dev/hello_misc",O_RDWR);if (fd < 0){printf("open error \n");return fd;}printf("open success \n");//字符串转化为整型buf[0] = atoi(argv[1]);printf("buf[0]  %d \n", buf[0]);write(fd,buf,sizeof(buf));close(fd);return 0;
}
  • 设备树
test1: test {#address-cells = <1>;#size-cells = <1>;compatible = "test";reg = <4 0xff790000 4 0xff790004>;};&test1 {compatible = "test1234";status = "okay";
};

设备树下的platform总线-21相关推荐

  1. 【正点原子MP157连载】第三十五章 设备树下的platform驱动编写-摘自【正点原子】STM32MP1嵌入式Linux驱动开发指南V1.7

    1)实验平台:正点原子STM32MP157开发板 2)购买链接:https://item.taobao.com/item.htm?&id=629270721801 3)全套实验源码+手册+视频 ...

  2. 设备树下的platform 驱动编写

    目录 设备树下的platform 驱动简介 硬件原理图分析 实验程序编写 修改设备树文件 platform 驱动程序编写 编写测试APP 运行测试 编译驱动程序和测试APP 运行测试 上一章我们详细的 ...

  3. 设备树下的 platform 驱动开发框架

    1. 设备树下的platform驱动开发 platform驱动框架分为总线.设备和驱动,其中总线是由Linux内核提供,在编写驱动时只要关注于设备和驱动的具体实现即可.Linux下的platform驱 ...

  4. Linux 设备树下的 platform 驱动实验基于正点原子IMX6ULL开发板

    1 设备树下的 platform 驱动简介 platform 驱动框架分为总线.设备和驱动,其中总线不需要我们这些驱动程序员去管理,这个是 Linux 内核提供的,我们在编写驱动的时候只要关注于设备和 ...

  5. Linux 设备树下的 platform 驱动示例

    1.简介 基于总线.设备和驱动这样的驱动框架,Linux 内核提出来 platform 这个虚拟总线,相应的也有 platform 设备和 platform 驱动. Linux 总线设备和驱动模式 2 ...

  6. 设备树下的platform驱动编写

    文章目录 一.设备树下的platform驱动简介 1.在设备树中创建设备节点 2.编写 platform 驱动的时候要注意兼容属性 3.编写platform驱动 二.硬件原理图分析 三.实验程序编写 ...

  7. 设备树下的 platform 驱动

    platform 设备驱动 Linux 系统要考虑到驱动的可重用性,因此提出了驱动的分离与分层这样的软件思路,在这个思路下诞生了我们将来最常打交道的platform 设备驱动,也叫做平台设备驱动. L ...

  8. I.MX6ULL ARM驱动开发---设备树下的platfrom设备驱动

    引言   最新的 Linux 内核已经支持了设备树,因此在设备树下如何编写 platform 驱动就显得尤为重要,本章我们就来学习一下如何在设备树下编写 platform 驱动. 一.设备树下的 pl ...

  9. 嵌入式实践教程--设备树下的I2C驱动开发

    Linux I2C 驱动框架简介 回想一下我们在裸机篇中是怎么编写 AP3216C 驱动的,我们编写了四个文件:bsp_i2c.c.bsp_i2c.h.bsp_ap3216c.c 和 bsp_ap32 ...

最新文章

  1. 一网打尽当下NoSQL类型、适用场景及使用公司
  2. [Js-Spring]Spring与IoC(控制反转,Inversion of Control)
  3. 动态规划(dynamic programming)基础【背包问题】
  4. 基于 DataLakeAnalytics 做跨地域的数据分析
  5. Power Strings POJ - 2406(求一串字符串中有多少个循环节)
  6. 摆脱困境:在DbUnit数据集中使用空值
  7. hadoop--Map Join
  8. 截至2020年底Cosmos生态基金会ICF总资金达2.12亿美元 加密资产占82%
  9. while语句,do-while与for循环的介绍
  10. `find -name`模式匹配多个模式
  11. POJ 3415 (后缀数组)
  12. 二次元始,跌宕几年,至学术略有成就并步入业界的我与NLP的这七年时光!
  13. python 面板数据分析_stata面板数据模型分析的详细步骤和命令
  14. android手机屏分辨率和屏幕逻辑,手机屏幕分辨率术语:逻辑分辨率和物理分辨率...
  15. Vue使用Upload上传图片报错:TypeError: Cannot create property 'xxx' on string 'xxxx'
  16. Ubuntu下安装新版QQ
  17. tensorflow conv2d()参数解析
  18. 【JavaWeb】之Tomcat介绍、安装与使用
  19. 手机支付商业模式剖析
  20. 2021-2025年中国SWIR-InGaAs光电二极管线阵行业市场供需与战略研究报告

热门文章

  1. js实现移动端电子签名
  2. 谷歌地图营销.Google竞价排名
  3. U盘启动盘重装win7/10系统
  4. ORACLE ERP 的前世今生摘记及原文
  5. 百趣代谢组学资讯:项目文章Nature,揭示低温暴露抑制实体瘤生长机制,‘饿死’癌细胞
  6. python99乘法表四种_Python 99乘法表实现的两种方式
  7. [WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
  8. 【末日时在做什么?有没有空?可以来拯救吗?】Scarborough Fair
  9. 基于Java实现的贪吃蛇大作战小游戏
  10. JAVA 实现《贪吃蛇大作战》游戏|CSDN创作打卡