-hi3516a标准简单版i2c设备驱动

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u013308744/article/details/77045726

设备驱动如下:


 
 
  1. #include <linux/kernel.h>
  2. #include <linux/version.h>
  3. #include <linux/module.h>
  4. #include <linux/types.h>
  5. #include <linux/errno.h>
  6. #include <linux/fcntl.h>
  7. #include <linux/mm.h>
  8. #include <linux/proc_fs.h>
  9. #include <linux/fs.h>
  10. #include <linux/slab.h>
  11. //#include <linux/smp_lock.h>
  12. #include <linux/init.h>
  13. #include <asm/uaccess.h>
  14. #include <asm/io.h>
  15. //#include <asm/system.h>
  16. #ifndef CONFIG_HISI_SNAPSHOT_BOOT
  17. #include <linux/miscdevice.h>
  18. #endif
  19. #include <linux/delay.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/poll.h>
  22. #include <asm/bitops.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/irq.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/ioport.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/reboot.h>
  29. #include <linux/notifier.h>
  30. #include <linux/i2c.h>
  31. #include <linux/i2c-dev.h>
  32. #include "tlv320aic31.h"
  33. #define CHIP_NUM 1
  34. #define DEV_NAME "tlv320aic31"
  35. static struct i2c_board_info hi_info =
  36. {
  37. I2C_BOARD_INFO( "adv7180", 0x40),
  38. };
  39. static struct i2c_client* tlv_client;
  40. int tlv320aic31_write(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
  41. {
  42. int ret;
  43. unsigned char buf[ 2];
  44. struct i2c_client* client = tlv_client;
  45. printk( "matt-tlv320aic31_write\n");
  46. buf[ 0] = reg_addr;
  47. buf[ 1] = value;
  48. ret = i2c_master_send(client, buf, 2);
  49. return ret;
  50. }
  51. EXPORT_SYMBOL(tlv320aic31_write);
  52. /*struct i2c_client* matt_getclient(void)
  53. {
  54. struct i2c_client* client = tlv_client;
  55. return client;
  56. }
  57. EXPORT_SYMBOL(matt_getclient);*/
  58. int tlv320aic31_read(unsigned char chip_addr, char reg_addr)
  59. {
  60. int ret;
  61. char *tmp;
  62. tmp=&reg_addr;
  63. // unsigned char buf[2];
  64. struct i2c_client* client = tlv_client;
  65. //ret = i2c_master_send(client, &addr, 1);
  66. //buf[0]=addr;
  67. //buf[1]=addr;
  68. // printk("matt-ret=%d,val=%x\n",ret,*val);
  69. printk( "matt-ret=%d,val=%x\n",ret,*tmp);
  70. ret = i2c_master_recv(client, tmp, 1);
  71. printk( "matt-ret1=%d,val=%x\n",ret,*tmp);
  72. return ret;
  73. }
  74. EXPORT_SYMBOL(tlv320aic31_read);
  75. /*void adv7180_Reset()
  76. {
  77. writel(0x00000000, IO_ADDRESS(0x200f00f4));
  78. writel(0x00000008, IO_ADDRESS(0x201f0400));
  79. writel(0x00000000, IO_ADDRESS(0x201f0020));
  80. msleep(10);
  81. writel(0x000000FF, IO_ADDRESS(0x201f0020));
  82. }*/
  83. static int __ init tlv320aic31_init(void)
  84. {
  85. struct i2c_adapter* i2c_adap=NULL;
  86. int temp = 0;
  87. u8 val1= 0;
  88. printk( "matt-tlv320aic31_init+1\n");
  89. //adv7180_Reset();
  90. // use i2c2
  91. i2c_adap = i2c_get_adapter( 2);
  92. tlv_client = i2c_new_device(i2c_adap, &hi_info);
  93. i2c_put_adapter(i2c_adap);
  94. temp = tlv320aic31_write( 0x40, 0x00, 0x03);
  95. printk( "matt-temp=%x\n",temp);
  96. temp = tlv320aic31_read( 0x40, 0x00);
  97. printk( "matt-temp1=%x\n",temp);
  98. return 0;
  99. }
  100. static void __ exit tlv320aic31_exit(void)
  101. {
  102. i2c_unregister_device(tlv_client);
  103. printk( "rmmod tlv320aic31.ko for Hi3516A ok!\n");
  104. }
  105. module_init(tlv320aic31_init);
  106. module_exit(tlv320aic31_exit);
  107. MODULE_LICENSE( "GPL");
  108. MODULE_AUTHOR( "Hisilicon");


这是最简单版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值