当前位置:网站首页>Gslx680 touch screen driver source code analysis (gslx680. C)

Gslx680 touch screen driver source code analysis (gslx680. C)

2022-07-07 07:39:00 Snail taking off

1、 Overall analysis of touch screen code

(1)gslx680 The touch screen is I2C Interface device , So the driver code uses I2C Interface provided by subsystem , use I2C Provided by the core layer I2C The driver registration interface will be built I2C Drive the structure to I2C Subsystem registration ;】
(2) Registered touch screen I2C The driver will be in I2C On the bus and corresponding I2C Device matching , To call I2C Driven probe Method ;
(3)I2C The subsystem is in the whole touch screen driver code , Just responsible for I2C Equipment and master control Soc Communication for , The whole touch screen code also involves input The subsystem is used to report the touch time to the upper application , The interrupt subsystem is used to process the interrupt of the touch screen ;

2、 Touch screen driver registration function

static struct i2c_driver gsl_ts_driver = {
    
	.driver = {
    
		.name = GSLX680_I2C_NAME,
		.owner = THIS_MODULE,
	},
#ifndef CONFIG_HAS_EARLYSUSPEND
	.suspend	= gsl_ts_suspend,
	.resume	= gsl_ts_resume,
#endif
	.probe		= gsl_ts_probe,
	.remove		= __devexit_p(gsl_ts_remove),
	.id_table	= gsl_ts_id,
};

static int __init gsl_ts_init(void)
{
    
    int ret;
	print_info("==gsl_ts_init==\n");
	
	ret = i2c_add_driver(&gsl_ts_driver);
	
	print_info("ret=%d\n",ret);
	return ret;
}

The function of the registration function is to I2C The subsystem is registered with the name gsl_ts_driver Of I2C drive ;

3、 Touch screen driven probe function

// stay gslx680 Touch screen driver is used to describe I2C Driven structure 
struct gsl_ts {
    
	struct i2c_client *client;
	struct input_dev *input;
	struct work_struct work;
	struct workqueue_struct *wq;
	struct gsl_ts_data *dd;
	u8 *touch_data;
	u8 device_id;
	int irq;
#if defined(CONFIG_HAS_EARLYSUSPEND)
	struct early_suspend early_suspend;
#endif
};

static int __devinit gsl_ts_probe(struct i2c_client *client,
			const struct i2c_device_id *id)
{
    
	struct gsl_ts *ts;
	int rc;

	······

	// Check whether the adapter supports the standard I2C Communication protocol 
	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
    
		dev_err(&client->dev, "I2C functionality not supported\n");
		return -ENODEV;
	}
 
	ts = kzalloc(sizeof(*ts), GFP_KERNEL);
	if (!ts)
		return -ENOMEM;
	print_info("==kzalloc success=\n");

	// take client Save to ts In the structure 
	ts->client = client;
	
	// hold ts Save to client->dev Private data for 
	i2c_set_clientdata(client, ts);
	ts->device_id = id->driver_data;

	// register input Subsystem , Initialize work queue , Bind the lower half of the touch screen interrupt 
	rc = gslX680_ts_init(client, ts);
	if (rc < 0) {
    
		dev_err(&client->dev, "GSLX680 init failed\n");
		goto error_mutex_destroy;
	}	

	gsl_client = client;

	// Set touch screen related GPIO Pin 
	gslX680_init();

	// Initialize by reading and writing the registers related to the touch screen chip 
	init_chip(ts->client);
	
	check_mem_data(ts->client);

	// Apply for interrupt number and bind interrupt handler 
	rc=  request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING, client->name, ts);
	if (rc < 0) {
    
		print_info( "gsl_probe: request irq failed\n");
		goto error_req_irq_fail;
	}

	······
}

(1) towards I2C Core layer registered I2C The touch screen driver will eventually be I2C Match on the bus I2C equipment , That is to say struct i2c_client Structure ;
(2)I2C The bus will call I2C Driven probe Method , Match it struct i2c_client The structure is passed in ;
(3)probe Function will complete the initialization , These include input Subsystem registration , Interrupt the registration of the program ;

4、 Interrupt handling function

static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
{
    	
	struct gsl_ts *ts = dev_id;

	print_info("========gslX680 Interrupt=========\n");				 

	// No interruptions 
	disable_irq_nosync(ts->irq);

	// Detect whether the work queue to which the lower half of the interrupt belongs is suspended , If suspended, add the lower half of the interrupt to the queue for scheduling 
	// Call the lower half of the interrupt function , That is to say gslX680_ts_worker()
	if (!work_pending(&ts->work)) 
	{
    
		queue_work(ts->wq, &ts->work);
	}
	
	return IRQ_HANDLED;

}

(1)gsl_ts_irq() Function is only the upper half of the interrupt handler , The actual function is to prohibit interruption , Then call the lower half of the interrupt ;
(2)gslX680_ts_worker() Is the bottom half of the interruption , stay gslX680_ts_init() Function ;
Add : Reference blog :《 The top half and bottom half of the interrupt are introduced and the implementation method (tasklet and Work queue )》;

5、 The logic of the whole touch screen driver code

gsl_ts_irq()	// Break the top half 
	gslX680_ts_worker()	// Break the bottom half 
		gsl_ts_write()	// Touch screen driven write data 
			i2c_master_send()	// The actual call I2C The data interface of the core layer 
		gsl_ts_read()	// Touch screen driven data reading 
			i2c_master_recv()	// The actual call I2C Data receiving interface of core layer 
		report_data()	// Report data 
			input_report_abs()	// The actual call input Reporting interface of subsystem 

(1) When a touch event occurs on the touch screen , The interrupt handler that triggers the binding gsl_ts_irq();
(2)gsl_ts_irq() Is to interrupt the upper half , Disable the interrupt and then call the lower half of the interrupt gslX680_ts_worker();
(3)gslX680_ts_worker() The function passes through I2C The subsystem provides I2C Bus transceiver data interface function , Read and write the relevant registers of the touch screen chip ;
(4)gslX680_ts_worker() The function calculates and converts the data read from the touch screen chip , Then fill in the input event structure , According to the previously registered input Subsystem , Press input The input events of the subsystem are reported to the application layer ;

原网站

版权声明
本文为[Snail taking off]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070358273192.html