MTK8788,6765,通用平台的按键驱动添加

   日期:2020-11-05     浏览:102    评论:0    
核心提示:主要修改4个地方,两个设备树文件,makflle,以及按键的问件编译,\kernel-4.4\arch\arm64\boot\dts\mediatek\mt6771.dtsirqkey_drv:irqkey_drv {compatible = “new-mobi,irq_key_drv”;};\kernel-4.4\arch\arm64\boot\dts\mediatek\tb8788p1_64_bsp.dts&irqkey_drv {interrupt-parent = <&a

主要修改4个地方,两个设备树文件,makflle,以及按键的问件编译,
\kernel-4.4\arch\arm64\boot\dts\mediatek\mt6771.dts

irqkey_drv:irqkey_drv {
compatible = “new-mobi,irq_key_drv”;
};

\kernel-4.4\arch\arm64\boot\dts\mediatek\tb8788p1_64_bsp.dts

&irqkey_drv {
interrupt-parent = <&pio>;
interrupts = <91 IRQ_TYPE_EDGE_FALLING 91 0>;
pin91-gpios = <&pio 91 0>;

debounce = <10>;
pinctrl-names = "default","key_pin91_as_int", "key_pin91_output0","key_pin91_output1";
pinctrl-0 = <&key_pins_default>;
pinctrl-1 = <&key_pins_91_as_int>;
pinctrl-2 = <&key_pins_91_output0>;
pinctrl-3 = <&key_pins_91_output1>;

status = "okay";

};
&pio {
key_pins_default: keydefault {
};
key_pins_91_as_int: key_pins91asint@0 {
pins_cmd_dat {
pinmux = <PINMUX_GPIO91__FUNC_GPIO91>;
slew-rate = <0>;
bias-pull-up = <11>;
};
};
key_pins_91_output0: key_pins91output0 {
pins_cmd_dat {
pinmux = <PINMUX_GPIO91__FUNC_GPIO91>;
slew-rate = <1>;
output-low;
};
};
key_pins_91_output1: key_pins91output1 {
pins_cmd_dat {
pinmux = <PINMUX_GPIO91__FUNC_GPIO91>;
slew-rate = <1>;
output-high;
};
};

};

修改
kernel-4.4\drivers\misc\mediatek\Makefile
obj-y += newmobi_key/

再该\kernel-4.4\drivers\misc\mediatek\ 加入这个问件夹,并写一个makefile

kernel-4.4\drivers\misc\mediatek\newmobi_key\Makefile
obj-y += irq_key.o

kernel-4.4\drivers\misc\mediatek\newmobi_key\irq_key.c

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/log2.h>
#include <linux/delay.h>

#include <linux/dma-mapping.h>
#include <linux/gpio.h>
#include <linux/miscdevice.h>

#include <linux/platform_device.h>

#include <linux/gpio.h>
#include <linux/poll.h>
#include <linux/interrupt.h>

#include <linux/input.h>
#include <linux/ioport.h>
#include <linux/miscdevice.h>
#include <linux/uaccess.h>
#include <linux/proc_fs.h>

#include <linux/types.h>

#ifdef CONFIG_OF
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/of_gpio.h>

#endif

#if defined(CONFIG_MTK_LEGACY)
#include <mach/mt_gpio.h>
#include <cust_gpio_usage.h>
#endif
#include <linux/workqueue.h>
#include <linux/input.h>

#define irqkey_MODULE_NAME “irqkey_key” // Name of this driver module
#define NM_MISC_NAME “nm_miscdev”

void gpio_as_int(void);

typedef struct _keyinfo{
unsigned int gpio_num;
unsigned int gpio_irq;
unsigned int irkkey_eint_type;
unsigned int flag_active;
}_KEYINFO;

static _KEYINFO key1;

struct input_dev *irqkey_input;

static struct _KEYINFO *irq_pd1;

static struct timer_list buttons_timer1;

static unsigned int gpio_irq1;

unsigned int irqkey_debounce, irqkey_gpiopin;

static struct pinctrl *pinctrl1;
static struct pinctrl_state *pins_default;
static struct pinctrl_state *eint_pin91_as_int, *eint_pin91_output0, *eint_pin91_output1;

static int get_gpio_info(struct platform_device *pdev){
int ret = 0;
printk("%s – enter\n",func);
pinctrl1 = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(pinctrl1)) {
ret = PTR_ERR(pinctrl1);
printk("%s : fwq Cannot find touch pinctrl1!\n",func);
return ret;
}

pins_default = pinctrl_lookup_state(pinctrl1, "default");


eint_pin91_as_int = pinctrl_lookup_state(pinctrl1, "key_pin91_as_int");
if (IS_ERR(eint_pin91_as_int)) {
	ret = PTR_ERR(eint_pin91_as_int);
	printk("%s :fwq Cannot find touch pinctrl key_pin91_as_int!\n",__func__);
	return ret;
}
eint_pin91_output0 = pinctrl_lookup_state(pinctrl1, "key_pin91_output0");
if (IS_ERR(eint_pin91_output0)) {
	ret = PTR_ERR(eint_pin91_output0);
	printk("%s :fwq Cannot find touch pinctrl key_pin91_output0!\n",__func__);
	return ret;
}
eint_pin91_output1 = pinctrl_lookup_state(pinctrl1, "key_pin91_output1");
if (IS_ERR(eint_pin91_output1)) {
	ret = PTR_ERR(eint_pin91_output1);
	printk("%s :fwq Cannot find touch pinctrl key_pin91_output1!\n",__func__);
	return ret;
}
printk("%s -- end\n",__func__);
return true;

}

void gpio_as_int(void)
{
printk("%s – enter\n",func);
//pinctrl_select_state(pinctrl1, eint_pin93_as_int);
//pinctrl_select_state(pinctrl1, eint_pin94_as_int);
printk("%s – end\n",func);
}

irqreturn_t irqkey_irq_handler1(int irq, void *data)
{
printk("%s %d\n" , func,irq);
irq_pd1 = (struct _KEYINFO *)data;
if(gpio_get_value(key1.gpio_num) == 0)
{
irq_set_irq_type(gpio_irq1, IRQ_TYPE_LEVEL_HIGH);
}else
{
irq_set_irq_type(gpio_irq1, IRQ_TYPE_LEVEL_LOW);
}
mod_timer(&buttons_timer1, jiffies + msecs_to_jiffies(10));
return IRQ_HANDLED;

}

static void buttons_timer_function1(unsigned long data)
{
struct _KEYINFO * pindesc = irq_pd1;

if (!pindesc)
	return;

if (gpio_get_value(key1.gpio_num))
{
	input_report_key(irqkey_input,KEY_CAMERA, 0);
	printk("*******KEY_F1 0*************\n");
	input_sync(irqkey_input);	
	
}
else
{
	input_report_key(irqkey_input,KEY_CAMERA, 1);
	input_sync(irqkey_input);
	printk("*******KEY_F1 1*************\n");
	
}

}

bool irqkey_irq_registration(void)
{
int ret;
struct device_node *node = NULL;
int ints[5] = {0,0,0,0,0};
printk("%s – enter\n",func);

node = of_find_compatible_node(NULL, NULL, "new-mobi,irq_key_drv");


if (node) 
{
	ret = of_property_read_u32(node, "debounce", &irqkey_debounce);
	if (ret) {
		printk("%s of_property_read_u32_array fail, ret = %d\n", __func__,ret);
		return ret;
	}
	//irqkey_debounce = ints[1];
	key1.gpio_num = of_get_named_gpio(node, "pin91-gpios", 0);
	gpio_set_debounce(key1.gpio_num, irqkey_debounce);
	printk("%s gpio_set_debounce(ints[0]=%d, ints[1]=%d);\n", __func__,ints[0],ints[1]);
	gpio_irq1 = irq_of_parse_and_map(node, 0);
	if(!gpio_irq1){
		printk("%s : can`t irq_of_parse_and_map for abc \n", __func__);
		return false;
	}
	
	ret = request_irq(gpio_irq1, (irq_handler_t)irqkey_irq_handler1,IRQ_TYPE_NONE, "irqkey_eint_91", &key1);
	//ret = request_threaded_irq(gpio_irq1, irqkey_irq_handlerA, irqkey_irq_handler1,IRQF_TRIGGER_LOW,"irqkey_eint_6", &key1);

	if (ret) {
		printk("%s : EINT IRQ LINE NOT AVAILABLE, ret = %d\n", __func__, ret);
		return false;
	} 
	key1.gpio_irq = gpio_irq1;
	key1.irkkey_eint_type = IRQ_TYPE_EDGE_RISING;
	printk("%s : set EINT finished, irqkey_irq=%d", __func__,gpio_irq1);
}
else
	return false;

init_timer(&buttons_timer1);
buttons_timer1.function = buttons_timer_function1;
add_timer(&buttons_timer1);

printk("%s -- end\n",__func__);
return true;

}

static int irqkey_platform_probe(struct platform_device *pdev)
{
int err=0 ;
printk("%s – enter\n",func);
err = get_gpio_info(pdev);
if(!err){
printk("%s: get_gpio_info is failed err = %d\n “, func,err);
return 0;
}
irqkey_irq_registration();
printk(”%s – 00000\n",func);
irqkey_input= input_allocate_device();
if (!irqkey_input) {
err = -ENOMEM;
printk("%s: failed to allocate input device\n", func);
goto err_free_mem;
}
printk("%s – 11111\n",func);
irqkey_input->name = “nm_irqkey-key”;
irqkey_input->phys = “nm_irqkey irq-key/input0”;

__set_bit(EV_KEY, irqkey_input->evbit);
__set_bit(EV_SYN, irqkey_input->evbit);

__set_bit(KEY_CAMERA,irqkey_input->keybit);

printk("%s -- 2222\n",__func__);
err = input_register_device(irqkey_input);
if (err) {
	printk("%s unable to register input device\n",__func__);
	goto err_free_mem;
}

printk("%s -- end\n",__func__);
err_free_mem:
	input_free_device(irqkey_input);

return 0;

}
/----------------------------------------------------------------------------/
static int irqkey_platform_remove(struct platform_device *pdev)
{
return 0;
}
static struct of_device_id irqkey_of_match[] = {
{ .compatible = “new-mobi,irq_key_drv”, },
{ },
};

static struct platform_driver irqkey_platform_driver =
{
.probe = irqkey_platform_probe,
.remove = irqkey_platform_remove,
.driver =
{
.name = irqkey_MODULE_NAME,
.of_match_table = irqkey_of_match,
.owner = THIS_MODULE,

}

};

static int __init irqkey_mod_init(void)
{

printk("%s --\n",__func__);

if(platform_driver_register(&irqkey_platform_driver))
{
	printk("[NEI2C]%s failed to platform_driver_register driver \n",__func__);
	return -ENODEV;
}

return 0;

}

static void __exit irqkey_mod_exit(void)
{
printk("%s --\n",func);
platform_driver_unregister(&irqkey_platform_driver);

}

module_init(irqkey_mod_init);
module_exit(irqkey_mod_exit);

MODULE_DESCRIPTION(“newmobi i2c driver demo driver”);
MODULE_AUTHOR(“tangh@new-mobi.com”);
MODULE_LICENSE(“GPL v2”);

如果要增加,可以适当修改一下.

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服