AnsweredAssumed Answered

Instantiate I2C Device AD5933

Question asked by cboyce on Nov 14, 2017
Latest reply on Mar 2, 2018 by DragosB

I'm currently trying to get the Linux driver working for the AD5933 EBZ Eval board. I've gotten stuck at how to exactly instantiate it as an I2C device. I've read the link: instantiating-devices\i2c\Documentation - kernel/git/torvalds/linux.git - Linux kernel source tree but I'm still unsure about how to go about this.

 

Firstly, I've loaded the ad5933 module in to the kernel.

 

modprobe ad5933

 

Now, do I create another module with the following code, and load it into the kernel as well?

static struct i2c_board_info __initdata board_i2c_board_info[] = {
#if defined(CONFIG_AD5933) || defined(CONFIG_AD5933_MODULE)     
   {          
   I2C_BOARD_INFO("ad5933", 0x0D),          
   .platform_data = (void *)&ad5933_pdata, /* optional */    
   },
#endif}

static int __init board_init(void){     
[--snip--]       
   i2c_register_board_info(0, board_i2c_board_info,                   
   ARRAY_SIZE(board_i2c_board_info));     
   [--snip--]       return
0;}
arch_initcall(board_init);

I saw this post by Lars. I understand he is creating a module and then loading it into the kernel. However, is there a complete example of this code with the import statements and Makefile, since I haven't been able to find any other examples.

 

  1. static struct i2c_board_info __initdata adxl345_i2c_info[]={  
  2.      {  
  3.            I2C_BOARD_INFO("adxl34x"0x53),  
  4.            .irq = ADX345_IRQ_NR,  
  5.       },  
  6. };  
  7.   
  8. static i2c_client *adxl345_client;  
  9.   
  10. static int __init adxl345_i2c_init(void)  
  11. {  
  12.      adxl345_client = i2c_new_device(i2c_get_adapter(YOUR_I2C_BUS_NUM), adxl345_i2c_info);  
  13.      return 0;  
  14. }  
  15. module_init(adxl345_i2c_init);  
  16.   
  17. static void __init adxl345_i2c_exit(void)  
  18. {  
  19.      i2c_unregister_device(adxl345_client);  
  20. }  
  21. module_exit(adxl345_i2c_exit);  

 

- Lars

 

If anyone could walk me through this step on the wiki it would be greatly appreciated!

 

Thank you!

 

Cameron

Outcomes