Posted April 25, 201410 yr I am writing a driver for an external I2C bus device that resides on a custom computer board. There is an external connector on the device that provides an I2C bus interface. Obviously the Linux O/S does not know what device is on the bus so the driver needs to add its device to an existing bus. I have coded the following driver but the probe function is never called. What invokes the probe method to be called? Code: #ifndef __KERNEL__ # define __KERNEL__ #endif #ifndef MODULE # define MODULE #endif #include <linux/module.h> #include <linux/init.h> #include <linux/i2c.h> #include <linux/platform_device.h> #include <linux/kernel.h> #include "io60_com4_cfg.h" // Function prototypes for local functions // I2C Device Info struct i2c_board_info io60_com4_cfg_info[] = { { I2C_BOARD_INFO("max7310", 0x30) }, { I2C_BOARD_INFO("max7310", 0x32) }, { I2C_BOARD_INFO("max7310", 0x34) }, }; struct i2c_device_id io60_com4_cfg_id[] = { { "max7310", 0x30 }, { "max7310", 0x32 }, { "max7310", 0x34 }, {} }; MODULE_DEVICE_TABLE(i2c, io60_com4_cfg_id); // Probe Module nt io60_com4_cfg_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *bus; printk("<1>io60_com4_cfg: probed\n"); // Populate bus bus = i2c_get_adapter(2); if (!bus) { printk("<1>io60_com4_cfg: invalid i2c adapter\n"); return -ENODEV; } memset(&io60_com4_cfg_info, 0, sizeof(struct i2c_board_info)); client = i2c_new_device(bus, io60_com4_cfg_info); if (!client) { printk("<1>io60_com4_cfg: unable to add i2c device\n"); return -ENODEV; } return SUCCESS; } // Remove Module nt io60_com4_cfg_remove(struct i2c_client *client) { printk("<1>io60_com4_cfg: removed\n"); i2c_unregister_device(client); } // Driver Declarations struct i2c_driver io60_com4_cfg_driver = { .driver = { .name = "io60_com4_cfg", }, .probe = io60_com4_cfg_probe, .remove = io60_com4_cfg_remove, .id_table = io60_com4_cfg_id, }; // Init Module static int __init io60_com4_cfg_init(void) { // register the i2c chip driver printk("<1>io60_com4_cfg: init executed\n"); return i2c_add_driver(&io60_com4_cfg_driver); } // Cleanup Module static void __exit io60_com4_cfg_exit(void) { printk("<1>io60_com4_cfg: exit executed\n"); i2c_del_driver(&io60_com4_cfg_driver); } module_init(io60_com4_cfg_init); module_exit(io60_com4_cfg_exit); I attempted to move the get_adapter and add_new_device code pieces to the init function, but then the O/S will return a message that the driver does not exist. Any ideas would be appreciated. Continue reading...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.