要移植hall sensor的驱动,但手上没有源码,只能自己写了,但能不能偷懒呢。在github上搜索一番,还真找到了,分享下。
dts参考配置
hall {
compatible = "hall-switch";
linux,gpio-int=<&ap_gpio 45 1>;
linux,wakeup;
vddio=<&vddcama>;
linux,max-uv=<2800>;
linux,min-uv=<2800>;
};
如果sensor的电源是常供的,去掉vddiio,找不到该电源,系统会默认拿一路dummy的电源。
源码(原始代码只能亮屏不能灭屏,做了一下修改)
/*
*
* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/err.h>
#include <linux/errno.h>
#include <linux/input.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/pm.h>
#include <linux/module.h>
#include <linux/regulator/consumer.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#define LID_DEV_NAME "hall_sensor"
#define HALL_INPUT "/dev/input/hall_dev"
struct hall_data {
int gpio; /* device use gpio number */
int irq; /* device request irq number */
int active_low; /* gpio active high or low for valid value */
bool wakeup;

本文介绍了一种Hall传感器驱动的移植方法,包括从GitHub获取开源代码、解析设备树配置、初始化输入设备、设置中断处理程序、配置电压调节器等关键步骤。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



