Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Location
    Allen, TX
    Posts
    21

    Question I2C Driver for Add-In Device - Probe not being Called


    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.

  2. #2
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    I think you may need to call i2c_new_probed_device instead of i2c_new_device: https://www.kernel.org/doc/Documenta...iating-devices

  3. #3
    Just Joined!
    Join Date
    Nov 2010
    Location
    Allen, TX
    Posts
    21
    I agree that may be required but currently it does not matter because the probe function is never called.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    -->
    There are quite a few options in the link I provided. Have you read through them?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •