FT5406觸控螢幕驅動

來源:互聯網
上載者:User

學習要點:1、驅動程式進入點,在哪個階段被載入,如何調整驅動載入的先後;

2、裝置和驅動之間如何關聯上;

3、I2C匯流排的操作,I2C協議;

4、電源管理,包括電源的申請、開啟、待機處理等;

5、Input裝置的註冊,事件的上報;

6、多點觸摸裝置的事件,參數;

7、方向調整;


1.首先,分析下FT5406的基本電路介面

[html]
view plaincopy
  1. External Interface   
  2.     I2C/SPI: an interface for data exchange with host  
  3.     INT: an interrupt signal to inform the host processor that touch data is ready for read   
  4.     WAKE: an interrupt signal for the host to change F5x06 from Hibernate to Active mode   
  5.     /RST: an external low signal reset the chip.    

WAKE:主要靠cpu發送一個喚醒指令給FT5406。
INT:GPIO0_A2。
/RST:複位,先輸出低後輸出高電平。

2.需確認FT5406的從地址,以便於I2C訪問得到。這個可以根據FT5406資料手冊尋找到——0x38
    首先配置 i2c_board_info,把從地址提供過去。
    i2c_board_info用於構建資訊表來列出存在的I2C裝置。這一資訊用於增長新型I2C驅動的驅動模型樹。對於主板,它使用i2c_register_board_info()來靜態建立。對於子板,利用已知的適配器使用i2c_new_device()動態建立。
    //I2C 裝置建立模板

[html]
view plaincopy
  1. //mach-rk29/board-rk29-ddr3sdk.c  
  2. struct i2c_board_info {  
  3.     char type[I2C_NAME_SIZE];  //晶片類型,用於初始化i2c_client.name  
  4.     unsigned short flags;  //用於初始化i2c_client.flags  
  5.     unsigned short addr;  //儲存於i2c_client.addr  
  6.     void *platform_data;  //儲存於i2c_client.dev.platform_data  
  7.     struct dev_archdata *archdata;  //拷貝至i2c_client.dev.archdata  
  8.     int irq;  //儲存於i2c_client.irq  
  9. };  

//使用Linux I2C驅動棧,系統可以在初始化時宣告板載資訊表。這些應該在靠近arch_initcall()時的板子相關的初始化代碼或同等情況時,在I2C適配器驅動被註冊之前被執行。例如,主板初始化代碼可以定義幾個裝置,也可以在疊板的每個子板初始化代碼中定義。
//I2C裝置會在相關的匯流排適配器被註冊後建立。此後,標準驅動模型工具通常綁定新型I2C驅動至I2C裝置。對於使用這一函數宣告的裝置,在動態分配的情況下匯流排號是停用。
//傳遞的板子資訊可以安全的是__initdata,但是由於不能拷貝,要小心嵌入式指標(如platform_data,functions等)
//靜態宣告I2C裝置
在你對應的machine配置裡會執行“i2c_register_board_info”一個函數,它會將一個i2c_board_info的結構體註冊進系統,可以發現,在目錄/sys/bus/i2c/devices下的裝置就是這個i2c_board_info結構體裡所描述的I2C裝置,而/sys/bus/i2c/devices下的裝置名稱字就是根據i2c_board_info結構體中定義的I2C Address來命名的。
 
所以添加一個I2C裝置時,除了需要編寫這個I2C裝置的驅動之外,還需要在machine裡面加入I2C裝置的i2c_board_info內容。

[html]
view plaincopy
  1. int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned len);  
  2. @busnum: 指定這些裝置屬於哪個匯流排  
  3. @info: I2C裝置描述符向量  
  4. @len: 向量中描述符的數量;為了預留特定的匯流排號,可以是0。  
  5.    
  6.  i2c_register_board_info(0, i2c_devs0, ARRAY_SIZE(i2c_devs0));  
  7.   
  8. static struct i2c_board_info __initdata board_i2c0_devices[] = {  
  9. #if defined (CONFIG_TOUCHSCREEN_FT5406)  
  10.     {  
  11.         .type   ="ft5x0x_ts",  
  12.         .addr   = 0x38,    //0x70,  
  13.         .flags      =0,  
  14.         .irq        =RK29_PIN0_PA2, // support goodix tp detect, 20110706  
  15.         .platform_data = &ft5406_info,  
  16.     },  
  17. }  
  18.   
  19. struct ft5406_platform_data ft5406_info = {  
  20.   .init_platform_hw= ft5406_init_platform_hw, // TOUCH_RESET_PIN為輸出,並先置高後置低;TOUCH_INT_PIN為輸入IO。  
  21.   .exit_platform_hw= ft5406_exit_platform_hw,  
  22.   .platform_sleep  = ft5406_platform_sleep,  
  23.   .platform_wakeup = ft5406_platform_wakeup,  
  24. };  

核心配置項中:
CONFIG_TOUCHSCREEN_FT5406:   
\kernel\drivers\input\touchscreen
obj-$(CONFIG_TOUCHSCREEN_FT5406) += ft5x0x_i2c_ts.o

[html]
view plaincopy
  1. fts_ts_probe(,)  
  2.     pdata->init_platform_hw();   //初始化IO口  
  3.     gpio_to_irq(client->irq);    //設定IO口為IRQ  
  4.     request_irq(_sui_irq_num, fts_ts_irq, GPIOEdgelFalling, client->dev.driver->name, ft5x0x_ts);  
  5.             //    中斷號     中斷處理函數    下降沿觸發  
  6.     disable_irq(_sui_irq_num);  //關中斷  
  7.     input_allocate_device();    //分配輸入子系統  
  8.     __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);    //配置響應的事件類型  
  9.     __set_bit(EV_ABS, input_dev->evbit);  
  10.     input_set_abs_params(input_dev,  
  11.             ABS_MT_POSITION_X, 0, SCREEN_MAX_X/* + SCREEN_BOUNDARY_ADJUST_VALUE*/, 0, 0);  
  12.     input_set_abs_params(input_dev,  
  13.             ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y/* + SCREEN_BOUNDARY_ADJUST_VALUE*/, 0, 0);  
  14.     input_mt_init_slots(input_dev, CFG_MAX_POINT_NUM);  
  15.     input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);  
  16.     input_register_device(input_dev);   //註冊輸入裝置  
  17.            ft5x0x_ts->early_suspend.suspend = ft5x0x_ts_early_suspend;  
  18.          ft5x0x_ts->early_suspend.resume = ft5x0x_ts_late_resume;  
  19.          init_timer(&ft5x0x_ts_timer);      
  20.          ft5x0x_ts_timer.function = ft5x0x_ts_do_timer; //fts_ts_release();逾時未釋放則釋放中斷  
  21.     enable_irq(_sui_irq_num);   

 

[html]
view plaincopy
  1. irqreturn_t fts_ts_irq(int irq, void *dev_id)  
  2.     queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);  //具體任務是fts_work_func  
  3.         //fts_work_func(,)  
  4.         mod_timer(&ft5x0x_ts_timer ,jiffies + 6);  
  5.         fts_read_data();      
  6.         enable_irq(this_client->irq); 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.