海思35系列平台Tsensor驱动开发(1)驱动编写

1. 前言

3559平台芯片内部内置了温度传感器,可用于实时检测芯片内部温度;

温度的检测范围为-40~125℃,支持设置温度上下限阈值报警输出。内部温度传感器提供了单次采集模式和循环采集模式两种选择。

软件开发分为驱动和用户态软件开发。

2. 查看芯片datasheet

海思35系列平台Tsensor驱动开发(1)驱动编写

3. 驱动软件编写

这里使用混杂设备进行驱动编写;

misc_register(&hitsensor_dev);

以下就是具体功能实现,主要根据芯片datasheet转化过来;

(1)设置温度采集模式 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); SYS_READ(tsensor_reg_base+0x70); //MISC_CTRL28 if(hitsensor_info.value == 1) { reg_data |= 1 << 30; } else { reg_data &= ~(1 << 30); } SYS_WRITEL(tsensor_reg_base+0x70, reg_data); (2)设置温度采集周期 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); tmp = (hitsensor_info.value >> 1) | 0x1; tmp = tmp & 0xFF; reg_data = SYS_READ(tsensor_reg_base+0x70); //MISC_CTRL28 reg_data &= 0xF0FFFFFF; reg_data |= tmp << 20; SYS_WRITEL(tsensor_reg_base+0x70, reg_data); (3)设置温度报警上限阈值 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); reg_data = (hitsensor_info.value&0x3FF) << 10; SYS_WRITEL(tsensor_reg_base+0x70, reg_data); (4)设置温度报警下线阈值 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); reg_data = SYS_READ(tsensor_reg_base+0x70); reg_data |= hitsensor_info.value&0x3FF; SYS_WRITEL(tsensor_reg_base+0x70, reg_data); (5)使能启动温度采集 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); reg_data = SYS_READ(tsensor_reg_base+0x70); //MISC_CTRL28 if(hitsensor_info.value == 1) { reg_data |= 1 << 31; } else { reg_data &= ~(1 << 31); } SYS_WRITEL(tsensor_reg_base+0x70, reg_data); (6)读取CPU温度值 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); tmp = SYS_READ(tsensor_reg_base+0x78); //MISC_CTRL30 hitsensor_info.value = tmp & 0x3FF; copy_to_user((void __user *)arg, &hitsensor_info, sizeof(Hi_Tsensor_info)); } (7)读取温度报警上限标志 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); tmp = SYS_READ(tsensor_reg_base+0x74); //MISC_CTRL29 hitsensor_info.value = tmp & 0x1; copy_to_user((void __user *)arg, &hitsensor_info, sizeof(Hi_Tsensor_info)); (8)读取温度报警下限标志 copy_from_user(&hitsensor_info, (Hi_Tsensor_info*)arg, sizeof(Hi_Tsensor_info)); tmp = SYS_READ(tsensor_reg_base+0x74); //MISC_CTRL29 hitsensor_info.value = (tmp >> 1) & 0x1; copy_to_user((void __user *)arg, &hitsensor_info, sizeof(Hi_Tsensor_info));

至此驱动的具体功能都已实现

4. 驱动编译

这里驱动可以不放在内核编译; 可以参考35xx平台的驱动编译方式; 路径如下: drv/interdrv/sysconfig 【以sysconfig驱动为例】 参考这个Makefile即可

指定内核路径: KERNELDIR ?=/xxx/osdrv/opensource/kernel/linux-4.9.y_multi-core

指定交叉工具链: CROSS_COMPILE ?=aarch64-himix100-linux-

完整Makefile如下

DRIVER_NAME = hi_tsensor PWD = $(shell pwd) export ARCH=arm64 CROSS_COMPILE ?=aarch64-himix100-linux- #KERNELDIR ?= /lib/modules/$(shell uname -r)/build KERNELDIR ?=/xxx/xxx/osdrv/opensource/kernel/linux-4.9.y_multi-core EXE = $(DRIVER_NAME).ko obj-m := $(DRIVER_NAME).o hi_tsensor-objs := Hi_Tsensor.o .PHONY: all all: @echo ” Making $@ …” ifneq ($(CROSS_COMPILE),) $(MAKE) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules else $(MAKE) -C $(KERNELDIR) M=$(PWD) modules endif ifneq ($(OUT),) cp -f $(EXE) $(OUT)/ endif ifneq ($(INC),) cp -f *.h $(INC)/ endif .PHONY: clean clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers *.ko.unsigned depend .depend dep: $(CC) $(CFLAGS) -M *.c > .depend ifeq (.depend,$(wildcard .depend)) include .depend endif
<

编译完成,生成驱动ko文件

免责声明:文章内容来自互联网,本站不对其真实性负责,也不承担任何法律责任,如有侵权等情况,请与本站联系删除。
转载请注明出处:海思35系列平台Tsensor驱动开发(1)驱动编写 https://www.yhzz.com.cn/a/17259.html

上一篇 2023-05-20
下一篇 2023-05-20

相关推荐

联系云恒

在线留言: 我要留言
客服热线:400-600-0310
工作时间:周一至周六,08:30-17:30,节假日休息。