mtk 5.1版本霍尔开关驱动的调试

时间:2024-03-30 07:54:01

mtk 5.1版本霍尔开关驱动的调试

1.原理
当一块通有电流的金属或半导体薄片垂直地放在磁场中时,薄片的两端就会产生电位差,这种现象就称为霍尔效应

2 项目要求:利用霍尔开关实现亮屏灭屏功能(盒盖灭屏,开盖亮屏)
3 原理图 (中断引脚)

mtk 5.1版本霍尔开关驱动的调试
这里看到霍尔开关的引脚对应是AG26这个引脚映射
mtk 5.1版本霍尔开关驱动的调试
查看引脚映射看到霍尔开关的中断脚是GPIO9
mtk 5.1版本霍尔开关驱动的调试

4配置dws文件(5.1版本的只需配置dws文件不用配置dts文件)
mtk 5.1版本霍尔开关驱动的调试
mtk 5.1版本霍尔开关驱动的调试
mtk 5.1版本霍尔开关驱动的调试

mtk 5.1版本霍尔开关驱动的调试

5 LCM驱动状态标志
alps\kernel-3.10\drivers\misc\mediatek\videox\mt6735\disp_lcm.c

int disp_lcm_suspend(disp_lcm_handle *plcm)
{
	DISPFUNC();
	LCM_DRIVER *lcm_drv = NULL;

	if(_is_lcm_inited(plcm))
	{
		lcm_drv = plcm->drv;
		if(lcm_drv->suspend)
		{
			lcm_drv->suspend();
		}
		else
		{
			DISPERR("FATAL ERROR, lcm_drv->suspend is null\n");
			return -1;
		}

		if(lcm_drv->suspend_power)
		{
			lcm_drv->suspend_power();
		}
		lcd_hall_status = TRUE;//lcm灭屏标志
		
		return 0;
	}
	else
	{
		DISPERR("lcm_drv is null\n");
		return -1;
	}
}

int disp_lcm_resume(disp_lcm_handle *plcm)
{
	DISPFUNC();
	LCM_DRIVER *lcm_drv = NULL;
	
	if(_is_lcm_inited(plcm))
	{
		lcm_drv = plcm->drv;

		if(lcm_drv->resume_power)
		{
			lcm_drv->resume_power();
		}
		
		if(lcm_drv->resume)
		{
			lcm_drv->resume();
		}
		else
		{
			DISPERR("FATAL ERROR, lcm_drv->resume is null\n");
			return -1;
		}
		lcd_hall_status = false;//lcm亮屏标志
		
		return 0;
	}
	else
	{
		DISPERR("lcm_drv is null\n");
		return -1;
	}
}

6 霍尔驱动代码
alps\kernel-3.10\drivers\misc\mediatek\keypad\kpd.c

static bool kpd_pwrkey_state = false;

static void kpd_hall_eint_handler_event(unsigned long data);
static DECLARE_TASKLET(kpde_hall_tasklet, kpd_hall_eint_handler_event, 0);
extern bool lcd_hall_status; //on 1 ;off 0 lcm屏亮灭标志位

void kpd_hall_eint_handler_event(unsigned long data){

	mt_eint_mask(CUST_EINT_MHALL_NUM); 

	kpd_pwrkey_state = !kpd_pwrkey_state;
	
	if(kpd_pwrkey_state)
	{  
		//printk("\n HALL \n ON GPIO status __PAUl__ %d\n",mt_get_gpio_in(GPIO_GSE_2_EINT_PIN));
		//open
	   if(!lcd_hall_status)
	   	{
		input_report_key(kpd_input_dev, KPD_PWRKEY_MAP, 1);		
		input_report_key(kpd_input_dev, KPD_PWRKEY_MAP, 0);
	   	}
		
		if((CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_LOW) || (CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_FALLING))
			mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_POS);
		else
			mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_NEG); 
	}
	else
	{
		//printk("\n HALL \n OFF GPIO status __PAUl__ %d\n",mt_get_gpio_in(GPIO_GSE_2_EINT_PIN));			 
		//close
		 if(lcd_hall_status)
	     {
			input_report_key(kpd_input_dev, KPD_PWRKEY_MAP, 1);		
			input_report_key(kpd_input_dev, KPD_PWRKEY_MAP, 0);
	     }
	
		 if((CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_LOW) || (CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_FALLING))
			mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_NEG); 
		else
			mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_POS);
	}
	input_sync(kpd_input_dev);
	kpd_print("report Linux keycode = %u\n", KPD_PWRKEY_MAP);

	mt_eint_unmask(CUST_EINT_MHALL_NUM);  

}
/***********************************************************************/

void mt_hall_eint_register(void){
	//mt_set_gpio_mode(GPIO_GSE_2_EINT_PIN, GPIO_GSE_2_EINT_PIN_M_EINT);
	//mt_set_gpio_dir(GPIO_GSE_2_EINT_PIN, GPIO_DIR_IN);
	//mt_set_gpio_pull_enable(GPIO_GSE_2_EINT_PIN, GPIO_PULL_ENABLE);
	//mt_set_gpio_pull_select(GPIO_GSE_2_EINT_PIN, GPIO_PULL_UP);

//这里表示低电平,下降沿触发
	if((CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_LOW) || (CUST_EINT_MHALL_TYPE & CUST_EINTF_TRIGGER_FALLING))
		kpd_pwrkey_state = false;  
	else
		kpd_pwrkey_state = true;
	mt_eint_registration(CUST_EINT_MHALL_NUM, CUST_EINT_MHALL_TYPE, kpd_hall_eint_handler_event, 0);
	mt_eint_set_hw_debounce(CUST_EINT_MHALL_NUM, 10);
	mt_eint_unmask(CUST_EINT_MHALL_NUM);


}

static void kpd_hall_eint_handler(void)
{
	tasklet_schedule(&kpde_hall_tasklet);
}



static int kpd_pdrv_probe(struct platform_device *pdev)
{
............
#ifdef CONFIG_OF
	r = request_irq(kp_irqnr, kpd_irq_handler, IRQF_TRIGGER_NONE, KPD_NAME, NULL);
#else
	r = request_irq(MT_KP_IRQ_ID, kpd_irq_handler, IRQF_TRIGGER_FALLING, KPD_NAME, NULL);
#endif
	if (r) {
		printk(KPD_SAY "register IRQ failed (%d)\n", r);
		misc_deregister(&kpd_dev);
		input_unregister_device(kpd_input_dev);
		return r;
	}
	mt_eint_register();


	printk("hall-eint register\r\n");
	mt_hall_eint_register();//霍尔中断注册
	
#ifndef KPD_EARLY_PORTING	/*add for avoid early porting build err the macro is defined in custom file */
	long_press_reboot_function_setting();	/* /API 4 for kpd long press reboot function setting */
#endif
	hrtimer_init(&aee_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	aee_timer.function = aee_timer_func;

............
}