Ft5406 touch screen driver

Source: Internet
Author: User

Learning points: 1. Driver entry point, at which stage is loaded, and how to adjust the sequence of driver loading;

2. How are devices and drivers associated;

3. I2C bus operation, I2C protocol;

4. Power Management, including power application, power on, and standby processing;

5. input device registration and event reporting;

6. multi-touch device events and parameters;

7. Adjust the direction;


1. First, analyze the basic circuit interface of 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: the CPU sends a wake-up command to ft5406.
INT: gpio0_a2.
/Rst: reset. output is low first and output is high.

2. Confirm the slave address of ft5406.To facilitate I2C access. You can find -- 0x38 in the ft5406 Data Manual.
Configure i2c_board_info to provide the slave address.
I2c_board_info is used to construct the information table to list the existing I2C devices. This information is used to increase the driver model tree of the new I2C driver. For the motherboard, it uses i2c_register_board_info () for static creation. For sub-boards, use known adapters to dynamically create using i2c_new_device.
// I2C device creation Template

[HTML]
View plaincopy
  1. /// Mach-rk29/board-rk29-ddr3sdk.c
  2. Struct i2c_board_info {
  3. Char type [i2c_name_size]; // chip type, used to initialize i2c_client.name
  4. Unsigned short flags; // used to initialize i2c_client.flags
  5. Unsigned short ADDR; // stored in i2c_client.addr
  6. Void * platform_data; // stored in i2c_client.dev.platform_data
  7. Struct dev_archdata * archdata; // copy to i2c_client.dev.archdata
  8. Int IRQ; // stored in i2c_client.irq
  9. };

// With the Linux I2C driver stack, the system can declare the onboard information table during initialization. These should be executed before the I2C Adapter Driver is registered in case of board-related initialization code or equivalent near arch_initcall. For example, the motherboard initialization code can define several devices or be defined in the initialization code of each sub-board of the stacked board.
// The I2C device will be created after the relevant bus adapter is registered. Subsequently, the standard driver model tool is usually bound to a new I2C driver to an I2C device. For devices declared using this function, the bus number is unavailable in the case of dynamic distribution.
// The passed Board information can be safe _ initdata, but because it cannot be copied, be careful with embedded pointers (such as platform_data and functions)
// Static I2C device announcement
In your machine configuration, you will execute the "i2c_register_board_info" function, which will register an i2c_board_info struct into the system. You can find that, the device in the/sys/bus/I2C/devices directory is the I2C device described in the i2c_board_info structure, the device names under/sys/bus/I2C/devices are named according to the I2C address defined in the i2c_board_info struct.
 
Therefore, when adding an I2C device, in addition to writing the driver of the I2C device, you also need to add the i2c_board_info content of the I2C device to the machine.

[HTML]
View plaincopy
  1. Int i2c_register_board_info (INT busnum, struct i2c_board_info const * info, unsigned Len );
  2. @ Busnum: Specifies the bus to which these devices belong.
  3. @ Info: I2C device descriptor Vector
  4. @ Len: Number of descriptors in the vector. to reserve a specific bus number, it can be 0.
  5. I2c_register_board_info (0, i2c_devs0, array_size (i2c_devs0 ));
  6. Static struct i2c_board_info _ initdata board_i2c0_devices [] = {
  7. # If defined (config_touchscreen_ft5406)
  8. {
  9. . Type = "ft5x0x_ts ",
  10. . ADDR = 0x38, // 0x70,
  11. . Flags = 0,
  12. . IRQ = maid, // support goodix TP detect, 20110706
  13. . Platform_data = & ft5406_info,
  14. },
  15. }
  16. Struct ft5406_platform_data ft5406_info = {
  17. . Init_platform_hw = ft5406_init_platform_hw, // touch_reset_pin is output, and the position is set to high and low first; touch_int_pin is input Io.
  18. . Exit_platform_hw = ft5406_exit_platform_hw,
  19. . Platform_sleep = ft5406_platform_sleep,
  20. . Platform_wakeup = ft5406_platform_wakeup,
  21. };

In the Kernel configuration item:
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 (); // initialize the IO port
  3. Gpio_to_irq (client-> IRQ); // set the IO port to IRQ.
  4. Request_irq (_ sui_irq_num, fts_ts_irq, gpioedgelfalling, client-> Dev. Driver-> name, ft5x0x_ts );
  5. // Triggered when the interrupt handler function drops along the interrupt number.
  6. Disable_irq (_ sui_irq_num); // disconnected
  7. Input_allocate_device (); // allocate the input subsystem
  8. _ Set_bit (input_prop_direct, input_dev-> propbit); // configure the event type of the response
  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, pai_max_point_num );
  15. Input_set_abs_params (input_dev, abs_mt_touchch_major, 0,255, 0, 0 );
  16. Input_register_device (input_dev); // register the input device
  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 (); release interrupted when the timeout period is not released
  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); // The task is 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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.