[rk3288—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);// 将设备标记为能够处理某个事件
	}
		
	
	
	
	
	
	
}

未完

你可能感兴趣的:(嵌入式学习,rockchip,android)