module probe not working

Steve Jardine sjardine at acm.org
Sat Oct 20 00:08:28 PDT 2012


Heya All,

   I have a module that I have written for an i2c device. It will load, but never gets into the probe routine. Any ideas?

It has this basic structure:

#include<linux/module.h>
#include<linux/delay.h>
#include<linux/err.h>
#include<linux/i2c.h>
#include<linux/interrupt.h>
#include<linux/kthread.h>
#include<linux/platform_device.h>


static int silly_probe(struct i2c_client *adapter,
		const struct i2c_device_id *device_id);
static int silly_remove(struct i2c_client *client);

static const struct i2c_device_id silly_id[] = { { "silly", 0 }, { }, };

static struct i2c_driver silly_driver = {
          .driver = {
                     .name = "silly",
                     .owner = THIS_MODULE,
                     },
          .probe = silly_probe,
          .remove = __devexit_p(silly_remove),
          .id_table = silly_id,
 };

static int silly_probe(struct i2c_client *client,
		const struct i2c_device_id *id) 
{
	char buf[10] = {0};
	int res;

	//Configure device
    buf[0]=0xE0;
    buf[1]=0x60;
    buf[2]=0xFC;
    buf[3]=0x0C;
    res=i2c_master_send(client, buf, 4);
 	if (res!= 4) {
        /* ERROR HANDLING: i2c transaction failed */
        printk(KERN_INFO "Failed to write to the i2c bus.\n");
    }
    return(res);
}

/*!
 * silly I2C detach function
 *
 * @param client            struct i2c_client *
 * @return  Error code indicating success or failure
 */
static int silly_remove(struct i2c_client *client) {
	char buf[10] = {0};
	int res;

	pr_info("*** %s", __FUNCTION__);
    buf[0]=0x20; // Shutdown 

    res=i2c_master_send(client, buf, 1);
 	if (res != 1) {
        /* ERROR HANDLING: i2c transaction failed */
        printk(KERN_INFO "Failed to write to the i2c bus.\n");
    }

    return(res);
}


static int __init silly_init(void)
 {
          /* register driver */
          int res = i2c_add_driver(&silly_driver);
          if (res<  0) {
                  printk(KERN_INFO "add silly i2c driver failed\n");
                  return -ENODEV;
          }
          printk(KERN_INFO "added silly i2c driver\n");
          return (res);
 }
 module_init(silly_init);

 static void __exit silly_exit(void)
 {
          printk(KERN_INFO "remove silly i2c driver.\n");
          /* reset the silly */
          i2c_del_driver(&silly_driver);
 }

 module_exit(silly_exit);

-- 
Steve Jardine <sjardine at acm.org>


More information about the Linux-users mailing list