I am trying to write a driver for my i2с device. But I got a dead-end problem, which I could not solve with the help of Google for several days.
In general, I simplified the code to a minimum to understand where exactly the error is.
#include <linux/i2c.h>
#include <linux/module.h>
static int my_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
pr_info("Probe function calledn");
// Add your probe implementation here
return 0; // Return 0 on success
}
static int my_i2c_remove(struct i2c_client *client)
{
pr_info("Remove function calledn");
// Add your remove implementation here
return 0; // Return 0 on success
}
static const struct i2c_device_id my_id_table[] = {
{ "my_i2c_device", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, my_id_table);
static struct i2c_driver my_i2c_driver = {
.driver = {
.name = "my_i2c_driver",
.owner = THIS_MODULE,
},
.probe = my_i2c_probe,
.remove = my_i2c_remove,
.id_table = my_id_table,
};
static int __init my_init(void)
{
return i2c_add_driver(&my_i2c_driver);
}
static void __exit my_exit(void)
{
i2c_del_driver(&my_i2c_driver);
}
module_init(my_init);
module_exit(my_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("Sample I2C Driver");
The constant error I get:
sudo make
make -C /lib/modules/6.6.37-v8+/build M=/home/pi/ForestBox/driver modules
make[1]: Entering directory '/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab'
CC [M] /home/pi/ForestBox/driver/RTC_PCF_Driver.o
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:29:14: error: initialization of ‘int (*)(struct i2c_client *)’ from incompatible pointer type ‘int (*)(struct i2c_client *, const struct i2c_device_id *)’ [-Werror=incompatible-pointer-types]
29 | .probe = my_i2c_probe,
| ^~~~~~~~~~~~
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:29:14: note: (near initialization for ‘my_i2c_driver.probe’)
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:30:15: error: initialization of ‘void (*)(struct i2c_client *)’ from incompatible pointer type ‘int (*)(struct i2c_client *)’ [-Werror=incompatible-pointer-types]
30 | .remove = my_i2c_remove,
| ^~~~~~~~~~~~~
/home/pi/ForestBox/driver/RTC_PCF_Driver.c:30:15: note: (near initialization for ‘my_i2c_driver.remove’)
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /home/pi/ForestBox/driver/RTC_PCF_Driver.o] Error 1
make[2]: *** [/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab/Makefile:1921: /home/pi/ForestBox/driver] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/home/pi/linux-4251c6ff2aa870ca9782abc0ecdf60eac3ba22ab'
make: *** [Makefile:5: all] Error 2
Here is the kernel version
pi@raspberrypi:~/ForestBox/driver $ uname -r
6.6.37-v8+
GCC version
pi@raspberrypi:~/ForestBox/driver $ gcc --version
gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I understand what the error is about, and that the signatures must match. and it seems to me that they are the same.
I tried to do the same on another fresh OS but same device and got the same error
I suspect there is a bug with the versions, but how can I check?
Mykola Grodskyi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1