AM335x(TQ335x)学习笔记——触摸屏驱动编写
时间:11-28
来源:互联网
点击:
- g,sizeof(config))<0){
- dev_err(dev,"FailedtoconfiguretheGT811,tryagain...");
- status=-EINVAL;
- }
- else{
- dev_info(dev,"Gt811configuesucceed");
- status=0;
- break;
- }
- }
- returnstatus;
- }
- staticstructgt811_ts_platdata*gt811_ts_parse_devtree(structi2c_client*client)
- {
- structdevice*dev=&client->dev;
- structdevice_node*node;
- structgt811_ts_platdata*pdata;
- enumof_gpio_flagsflags;
- node=dev->of_node;
- if(!node){
- dev_err(dev,"Theof_nodeisNULL.");
- returnERR_PTR(-ENODEV);
- }
- pdata=devm_kzalloc(dev,sizeof(structdevice_node),GFP_KERNEL);
- if(!pdata){
- dev_err(dev,"Noenoughmemoryleft.");
- returnERR_PTR(-ENOMEM);
- }
- pdata->reset_pin=of_get_gpio_flags(node,0,&flags);
- if(pdata->reset_pin<0){
- dev_err(dev,"GetRSTpinfailed!");
- returnERR_PTR(-EINVAL);
- }
- if(of_property_read_u32(node,"touchscreen-size-x",&pdata->size_x)){
- dev_err(dev,"Failedtogetthetouchscreenxsize.");
- returnERR_PTR(-EINVAL);
- }
- if(of_property_read_u32(node,"touchscreen-size-y",&pdata->size_y)){
- dev_err(dev,"Failedtogetthetouchscreenysize.");
- returnERR_PTR(-EINVAL);
- }
- if(of_property_read_u32(node,"touchscreen-size-p",&pdata->size_p)){
- pdata->size_p=255;
- }
- if(of_property_read_u32(node,"touchscreen-swap",&pdata->swap)){
- pdata->swap=1;
- }
- if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_x)){
- pdata->revert_x=1;
- }
- if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_y)){
- pdata->revert_y=1;
- }
- returnpdata;
- }
- staticintgt811_ts_probe(structi2c_client*client,conststructi2c_device_id*id)
- {
- structdevice*dev=&client->dev;
- structgt811_ts_platdata*pdata=dev_get_platdata(dev);
- structinput_dev*input;
- interror=0;
- if(!of_match_device(of_match_ptr(gt811_ts_of_match),dev)){
- dev_err(dev,"Failedtomatch.");
- return-EINVAL;
- }
- if(!pdata){
- pdata=gt811_ts_parse_devtree(client);
- if(IS_ERR(pdata)){
- dev_err(dev,"Getdevicedatafromdevicetreefailed!");
- error=-EINVAL;
- gotofailed_exit;
- }
- }
- pdata->client=client;
- i2c_set_clientdata(client,pdata);
- input=devm_input_allocate_device(dev);
- if(!input){
- dev_err(dev,"Failedtoallocateinputdevice");
- error=-ENOMEM;
- gotopdata_free;
- }
- pdata->input=input;
- input->name=client->name;
- input->id.bustype=BUS_I2C;
- input->id.product=0xBEEF;
- input->id.vendor=0xDEAD;
- input->dev.parent=&client->dev;
- __set_bit(EV_KEY,input->evbit);
- __set_bit(EV_ABS,input->evbit);
- __set_bit(BTN_TOUCH,input->keybit);
- input_set_abs_params(input,ABS_X,0,pdata->size_x,0,0);
- input_set_abs_params(input,ABS_Y,0,pdata->size_y,0,0);
- input_set_abs_params(input,ABS_MT_POSITION_X,0,pdata->size_x,0,0);
- input_set_abs_params(input,ABS_MT_POSITION_Y,0,pdata->size_y,0,0);
- error=input_mt_init_slots(input,5,INPUT_MT_DIRECT|INPUT_MT_DROP_UNUSED);
- if(error){
- dev_err(dev,"Failedtoinitializethemulti-touchslots.");
- gotoinput_free;
- }
- input_set_drvdata(input,pdata);
- error=input_register_device(input);
- if(error){
- dev_err(dev,"Registerinputdevicefailed!");
- gotoinput_free;
- }
- if(gt811_ts_initilize(client)){
- dev_err(dev,"FailedtoinitializeGT811.");
- }
- INIT_WORK(&pdata->work,gt811_ts_handler);
- error=devm_request_any_context_irq(dev,client->irq,gt811_ts_isr,
- IRQF_TRIGGER_FALLING,client->name,pdata);
- if(error){
- dev_err(dev,"Failedtorequestirq(number:%d)",client->irq);
- gotoinput_free;
- }
- return0;
- input_free:
- devm_kfree(dev,input);
- pdata_free:
- devm_kfree(dev,pdata);
- failed_exit:
- returnerror;
- }
- staticintgt811_ts_remove(structi2c_client*client)
- {
- structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
- devm_free_irq(&client->dev,client->irq,i2c_get_clientdata(client));
- input_unregister_device(pdata->input);
- devm_kfree(&client->dev,pdata);
- return0;
- }
- staticconststructi2c_device_idgt811_ts_id[]={
- {"gt811_ts",0},
- {}
- };
- staticstructi2c_drivergt811_ts_driver={
- .driver={
- .owner=THIS_MODULE,
- .name="gt811_ts",
- .of_match_table=of_match_ptr(gt811_ts_of_match),
- },
- .probe=gt811_t
AM335xTQ335x触摸屏驱动编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)
