Hi All,
I trying to write I2C client driver for BMP180.
Here is my Code.
#include <linux/module.h>
#include <linux/input.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
static int bmp_180_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct i2c_client *my_client = NULL;
printk("This is I2c Probong Function..\n");
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev, "i2c_check_functionality error\n");
return -EIO;
}
my_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
if (my_client == NULL) {
printk(KERN_ERR "%s: no memory\n", __func__);
return -ENOMEM;
}
my_client = client;
i2c_set_clientdata(client, my_client);
return 0;
}
static int bmp_180_i2c_remove(struct i2c_client *client)
{
struct i2c_client *my_client = i2c_get_clientdata(client);
printk("This is I2c Removing Function..\n");
kfree(my_client);
return 0;
}
static const struct i2c_device_id bmp_180_i2c_id[] = {
{ "bmp_180", 1 },
{ },
};
MODULE_DEVICE_TABLE(i2c, bmp_180_i2c_id);
static const struct of_device_id bmp_180_dt_ids[] = {
{ .compatible = "bosch,bmp_180", },
{ }
};
MODULE_DEVICE_TABLE(of, bmp_180_dt_ids);
static struct i2c_board_info bmp_i2c_devices[] __initdata = {
{
I2C_BOARD_INFO("bmp_180", 0xEF),
},
};
static struct i2c_driver bmp_180_i2c_driver = {
.driver = {
.name = "bmp_180",
.of_match_table = bmp_180_dt_ids,
},
.probe = bmp_180_i2c_probe,
.remove = bmp_180_i2c_remove,
.id_table = bmp_180_i2c_id,
};
//module_i2c_driver(bmp_180_i2c_driver);
static int __init my_init(void)
{
//i2c_register_board_info(0, bmp_i2c_devices,ARRAY_SIZE(bmp_i2c_devices));
struct i2c_client *client;
struct i2c_adapter *adapter = NULL;
printk(" BMP I2c Driver inserted to kernel \n");
i2c_add_driver(&bmp_180_i2c_driver);
adapter = i2c_get_adapter(2);
printk("i2c_get_adapter:- %p\n", adapter);
//if (!adapter) return -EINVAL;
//client = i2c_new_device(adapter, bmp_i2c_devices);
// printk("i2c_new_device:- %p\n", client);
//if (!client) return -EINVAL;
printk("This is BMP init\n");
return 0;
}
static void __exit my_exit(void)
{
i2c_del_driver(&bmp_180_i2c_driver);
printk("This is BMP Exit\n");
}
module_init(my_init);
module_exit(my_exit);
MODULE_DESCRIPTION("BMP 180 I2C Driver");
MODULE_AUTHOR("RAHUL GUPTA");
MODULE_LICENSE("GPL");
Output:-
[ 5887.459396] BMP I2c Driver inserted to kernel
[ 5887.459859] i2c_get_adapter:- dce88c70
[ 5887.459877] This is BMP init
Problem is that my probing function is not getting called.
Please guide me, where I am going Wrong.
Thanks Guys