Linux下的Hall sensor驱动

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

要移植hall sensor的驱动,但手上没有源码,只能自己写了,但能不能偷懒呢。在github上搜索一番,还真找到了,分享下。

https://github.com/Myself5/android_kernel_sony_msm8994_OM5Z_old/blob/master/drivers/input/hall_sensor.c

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;	
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值