[rk32880—Android6.0]按鍵控制分析

 

  /kernel/drivers/input/keyboard/rk_keys.c 

這個驅動程序使用的函數一覽:

/*
 devm_input_allocate_device - allocate managed input device
 @dev: device owning the input device being created

 Returns prepared struct input_dev or %NULL.

 Managed input devices do not need to be explicitly unregistered or
 freed as it will be done automatically when owner device unbinds from
 its driver (or binding fails). Once managed input device is allocated,
 it is ready to be set up and registered in the same fashion as regular
 input device. There are no special devm_input_device_[un]register()
 variants, regular ones work with both managed and unmanaged devices,
 should you need them. In most cases however, managed input device need
 not be explicitly unregistered or freed.

 NOTE: the owner device is set up as parent of input device and users
 should not override it.
*/
/*devm_input_allocate_device  - 分配受管理的輸入設備
  @dev:擁有正在創建的輸入設備的設備
返回準備好的struct input_dev或%NULL。 託管輸入設備不需要顯式取消註冊或釋放,因爲當所有者設備從其驅動程序解除綁定(或綁定失敗)時,它將自動完成。 一旦分配了受管理的輸入設備,就可以以與常規輸入設備相同的方式進行設置和註冊。 沒有特殊的devm_input_device_ [un] register()變體,如果需要,常規的變體可以與託管和非託管設備一起使用。 但是,在大多數情況下,託管輸入設備無需顯式取消註冊或釋放。
  注意:所有者設備被設置爲輸入設備的父設備,用戶不應覆蓋它。
*/
struct input_dev *devm_input_allocate_device(struct device *dev)

//input_allocate_device  - 爲新輸入設備分配內存
struct input_dev *input_allocate_device(void)

根據設備樹,匹配成功後調用  static int keys_probe(struct platform_device *pdev)

key_num = of_get_child_count(np);    獲取設備樹中key

of_get_child_count(np);
	 struct device_node *child;
	 int num = 0;
	 for_each_child_of_node(np, child)
		num++;


 

static int keys_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct device_node *np = pdev->dev.of_node;
	struct rk_keys_drvdata *ddata = NULL;
	struct input_dev *input = NULL;
	int i, error = 0;
	int wakeup, key_num = 0;
	key_num = of_get_child_count(np);
	ddata = devm_kzalloc(dev, sizeof(struct rk_keys_drvdata) +
		     key_num * sizeof(struct rk_keys_button),
		     GFP_KERNEL);
	input = devm_input_allocate_device(dev);
	platform_set_drvdata(pdev, ddata);
		dev_set_drvdata(&pdev->dev, data);
			device_private_init(dev);
			dev->p->driver_data = data;
	dev_set_drvdata(&pdev->dev, ddata);	//這個感覺多餘了
	
	ddata->nbuttons = key_num;
 	error = rk_keys_parse_dt(ddata, pdev);			
		for_each_child_of_node(node, child_node)	//遍歷設備樹的節點
	/* Enable auto repeat feature of Linux input subsystem */
  	if (ddata->rep)
  		__set_bit(EV_REP, input->evbit);		
	error = input_register_device(input);	//註冊輸入設備
	sinput_dev = input;
	
	for (i = 0; i < ddata->nbuttons; i++) {
		struct rk_keys_button *button = &ddata->button[i];
	
		if (button->code) {
			setup_timer(&button->timer,
					keys_timer, (unsigned long)button);
		}
	
		if (button->wakeup)
			wakeup = 1;
	
		input_set_capability(input, EV_KEY, button->code);// 將設備標記爲能夠處理某個事件
	}
		
	
	
	
	
	
	
}

未完

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章