Guest User

test114 driver

a guest
Oct 31st, 2012
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/slab.h>
  4. #include <linux/i2c.h>
  5. #include <linux/hwmon.h>
  6. #include <linux/hwmon-sysfs.h>
  7. #include <linux/err.h>
  8. #include <linux/mutex.h>
  9. #include <linux/device.h>
  10.  
  11. #define DRIVER_NAME "test114"
  12.  
  13. static struct timer_list test114_update_timer;
  14.  
  15. struct i2c_client *test114_i2c;
  16. void test114_update_device(unsigned long data)
  17. {
  18.     struct i2c_client *client = test114_i2c;
  19.     i2c_smbus_read_byte_data(client, 0);
  20.     mod_timer(&test114_update_timer, jiffies + msecs_to_jiffies(1000));
  21.     printk("Tick...\n");
  22. }
  23.  
  24. static int __devinit test114_probe(struct i2c_client *client,
  25.                   const struct i2c_device_id *id)
  26. {
  27.     int status;
  28.  
  29.     if (!i2c_check_functionality(client->adapter,
  30.                      I2C_FUNC_SMBUS_WORD_DATA)) {
  31.         dev_err(&client->dev, "adapter doesn't support SMBus word "
  32.             "transactions\n");
  33.         return -ENODEV;
  34.     }
  35.  
  36.     setup_timer(&test114_update_timer, test114_update_device, 0);
  37.    
  38.     status = mod_timer(&test114_update_timer, jiffies + msecs_to_jiffies(5000));
  39.  
  40.     test114_i2c = client;
  41.     dev_info(&client->dev, "initialized\n");
  42.  
  43.     return 0;
  44. }
  45.  
  46. static int __devexit test114_remove(struct i2c_client *client)
  47. {
  48.     del_timer(&test114_update_timer);
  49.     return 0;
  50. }
  51. static const struct i2c_device_id test114_id[] = {
  52.     { "test114", 0 },
  53.     { }
  54. };
  55. MODULE_DEVICE_TABLE(i2c, test114_id);
  56.  
  57. static struct i2c_driver test114_driver = {
  58.     .driver.name    = DRIVER_NAME,
  59.     .probe      = test114_probe,
  60.     .remove     = __devexit_p(test114_remove),
  61.     .id_table   = test114_id,
  62. };
  63.  
  64. static int __init test114_init(void)
  65. {
  66.     return i2c_add_driver(&test114_driver);
  67. }
  68. module_init(test114_init);
  69.  
  70. static void __exit test114_exit(void)
  71. {
  72.     i2c_del_driver(&test114_driver);
  73. }
  74. module_exit(test114_exit);
  75.  
  76. MODULE_AUTHOR("sza2");
  77. MODULE_DESCRIPTION("test114 driver");
  78. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment