During the development of Linux drivers, it is sometimes necessary to print some driver version information, which facilitates iteration and maintenance.
The following describes the implementation approach:
First, include the header file information
#include <linux/version.h>
#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x4)
Then, in the driver’s probe function or entry function
static int imx415_probe(struct i2c_client *client, const struct i2c_device_id *id) {
struct device *dev = &client->dev;
dev_info(dev, "driver version: %02x.%02x.%02x",
DRIVER_VERSION >> 16,
(DRIVER_VERSION & 0xff00) >> 8,
DRIVER_VERSION & 0x00ff);
}