微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AM335x(TQ335x)学习笔记——触摸屏驱动编写

AM335x(TQ335x)学习笔记——触摸屏驱动编写

时间:11-28 来源:互联网 点击:

  1. g,sizeof(config))<0){
  2. dev_err(dev,"FailedtoconfiguretheGT811,tryagain...");
  3. status=-EINVAL;
  4. }
  5. else{
  6. dev_info(dev,"Gt811configuesucceed");
  7. status=0;
  8. break;
  9. }
  10. }
  11. returnstatus;
  12. }
  13. staticstructgt811_ts_platdata*gt811_ts_parse_devtree(structi2c_client*client)
  14. {
  15. structdevice*dev=&client->dev;
  16. structdevice_node*node;
  17. structgt811_ts_platdata*pdata;
  18. enumof_gpio_flagsflags;
  19. node=dev->of_node;
  20. if(!node){
  21. dev_err(dev,"Theof_nodeisNULL.");
  22. returnERR_PTR(-ENODEV);
  23. }
  24. pdata=devm_kzalloc(dev,sizeof(structdevice_node),GFP_KERNEL);
  25. if(!pdata){
  26. dev_err(dev,"Noenoughmemoryleft.");
  27. returnERR_PTR(-ENOMEM);
  28. }
  29. pdata->reset_pin=of_get_gpio_flags(node,0,&flags);
  30. if(pdata->reset_pin<0){
  31. dev_err(dev,"GetRSTpinfailed!");
  32. returnERR_PTR(-EINVAL);
  33. }
  34. if(of_property_read_u32(node,"touchscreen-size-x",&pdata->size_x)){
  35. dev_err(dev,"Failedtogetthetouchscreenxsize.");
  36. returnERR_PTR(-EINVAL);
  37. }
  38. if(of_property_read_u32(node,"touchscreen-size-y",&pdata->size_y)){
  39. dev_err(dev,"Failedtogetthetouchscreenysize.");
  40. returnERR_PTR(-EINVAL);
  41. }
  42. if(of_property_read_u32(node,"touchscreen-size-p",&pdata->size_p)){
  43. pdata->size_p=255;
  44. }
  45. if(of_property_read_u32(node,"touchscreen-swap",&pdata->swap)){
  46. pdata->swap=1;
  47. }
  48. if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_x)){
  49. pdata->revert_x=1;
  50. }
  51. if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_y)){
  52. pdata->revert_y=1;
  53. }
  54. returnpdata;
  55. }
  56. staticintgt811_ts_probe(structi2c_client*client,conststructi2c_device_id*id)
  57. {
  58. structdevice*dev=&client->dev;
  59. structgt811_ts_platdata*pdata=dev_get_platdata(dev);
  60. structinput_dev*input;
  61. interror=0;
  62. if(!of_match_device(of_match_ptr(gt811_ts_of_match),dev)){
  63. dev_err(dev,"Failedtomatch.");
  64. return-EINVAL;
  65. }
  66. if(!pdata){
  67. pdata=gt811_ts_parse_devtree(client);
  68. if(IS_ERR(pdata)){
  69. dev_err(dev,"Getdevicedatafromdevicetreefailed!");
  70. error=-EINVAL;
  71. gotofailed_exit;
  72. }
  73. }
  74. pdata->client=client;
  75. i2c_set_clientdata(client,pdata);
  76. input=devm_input_allocate_device(dev);
  77. if(!input){
  78. dev_err(dev,"Failedtoallocateinputdevice");
  79. error=-ENOMEM;
  80. gotopdata_free;
  81. }
  82. pdata->input=input;
  83. input->name=client->name;
  84. input->id.bustype=BUS_I2C;
  85. input->id.product=0xBEEF;
  86. input->id.vendor=0xDEAD;
  87. input->dev.parent=&client->dev;
  88. __set_bit(EV_KEY,input->evbit);
  89. __set_bit(EV_ABS,input->evbit);
  90. __set_bit(BTN_TOUCH,input->keybit);
  91. input_set_abs_params(input,ABS_X,0,pdata->size_x,0,0);
  92. input_set_abs_params(input,ABS_Y,0,pdata->size_y,0,0);
  93. input_set_abs_params(input,ABS_MT_POSITION_X,0,pdata->size_x,0,0);
  94. input_set_abs_params(input,ABS_MT_POSITION_Y,0,pdata->size_y,0,0);
  95. error=input_mt_init_slots(input,5,INPUT_MT_DIRECT|INPUT_MT_DROP_UNUSED);
  96. if(error){
  97. dev_err(dev,"Failedtoinitializethemulti-touchslots.");
  98. gotoinput_free;
  99. }
  100. input_set_drvdata(input,pdata);
  101. error=input_register_device(input);
  102. if(error){
  103. dev_err(dev,"Registerinputdevicefailed!");
  104. gotoinput_free;
  105. }
  106. if(gt811_ts_initilize(client)){
  107. dev_err(dev,"FailedtoinitializeGT811.");
  108. }
  109. INIT_WORK(&pdata->work,gt811_ts_handler);
  110. error=devm_request_any_context_irq(dev,client->irq,gt811_ts_isr,
  111. IRQF_TRIGGER_FALLING,client->name,pdata);
  112. if(error){
  113. dev_err(dev,"Failedtorequestirq(number:%d)",client->irq);
  114. gotoinput_free;
  115. }
  116. return0;
  117. input_free:
  118. devm_kfree(dev,input);
  119. pdata_free:
  120. devm_kfree(dev,pdata);
  121. failed_exit:
  122. returnerror;
  123. }
  124. staticintgt811_ts_remove(structi2c_client*client)
  125. {
  126. structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
  127. devm_free_irq(&client->dev,client->irq,i2c_get_clientdata(client));
  128. input_unregister_device(pdata->input);
  129. devm_kfree(&client->dev,pdata);
  130. return0;
  131. }
  132. staticconststructi2c_device_idgt811_ts_id[]={
  133. {"gt811_ts",0},
  134. {}
  135. };
  136. staticstructi2c_drivergt811_ts_driver={
  137. .driver={
  138. .owner=THIS_MODULE,
  139. .name="gt811_ts",
  140. .of_match_table=of_match_ptr(gt811_ts_of_match),
  141. },
  142. .probe=gt811_t

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top