版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
设备驱动如下:
-
#include <linux/kernel.h>
-
-
#include <linux/version.h>
-
-
#include <linux/module.h>
-
-
#include <linux/types.h>
-
-
#include <linux/errno.h>
-
-
#include <linux/fcntl.h>
-
-
#include <linux/mm.h>
-
-
#include <linux/proc_fs.h>
-
-
#include <linux/fs.h>
-
-
#include <linux/slab.h>
-
-
//#include <linux/smp_lock.h>
-
-
#include <linux/init.h>
-
-
#include <asm/uaccess.h>
-
-
#include <asm/io.h>
-
-
//#include <asm/system.h>
-
-
#ifndef CONFIG_HISI_SNAPSHOT_BOOT
-
-
#include <linux/miscdevice.h>
-
-
#endif
-
-
#include <linux/delay.h>
-
-
-
-
#include <linux/proc_fs.h>
-
-
#include <linux/poll.h>
-
-
-
-
#include <asm/bitops.h>
-
-
#include <asm/uaccess.h>
-
-
#include <asm/irq.h>
-
-
#include <linux/moduleparam.h>
-
-
#include <linux/ioport.h>
-
-
#include <linux/interrupt.h>
-
-
#include <linux/reboot.h>
-
-
#include <linux/notifier.h>
-
-
#include <linux/i2c.h>
-
-
#include <linux/i2c-dev.h>
-
-
#include "tlv320aic31.h"
-
-
-
-
#define CHIP_NUM 1
-
-
#define DEV_NAME "tlv320aic31"
-
-
-
-
static
struct i2c_board_info hi_info =
-
-
{
-
-
I2C_BOARD_INFO(
"adv7180",
0x40),
-
-
};
-
-
-
-
static
struct i2c_client* tlv_client;
-
-
-
-
int tlv320aic31_write(unsigned char chip_addr, unsigned char reg_addr, unsigned char value)
-
-
{
-
-
int ret;
-
-
unsigned
char buf[
2];
-
-
struct i2c_client* client = tlv_client;
-
-
printk(
"matt-tlv320aic31_write\n");
-
-
buf[
0] = reg_addr;
-
-
buf[
1] = value;
-
-
-
-
ret = i2c_master_send(client, buf,
2);
-
-
return ret;
-
-
}
-
-
EXPORT_SYMBOL(tlv320aic31_write);
-
-
/*struct i2c_client* matt_getclient(void)
-
-
{
-
-
struct i2c_client* client = tlv_client;
-
-
return client;
-
-
-
-
}
-
-
EXPORT_SYMBOL(matt_getclient);*/
-
-
-
-
int tlv320aic31_read(unsigned char chip_addr, char reg_addr)
-
-
{
-
-
-
-
int ret;
-
char *tmp;
-
tmp=®_addr;
-
// unsigned char buf[2];
-
-
struct i2c_client* client = tlv_client;
-
-
//ret = i2c_master_send(client, &addr, 1);
-
-
//buf[0]=addr;
-
//buf[1]=addr;
-
-
// printk("matt-ret=%d,val=%x\n",ret,*val);
-
printk(
"matt-ret=%d,val=%x\n",ret,*tmp);
-
-
ret = i2c_master_recv(client, tmp,
1);
-
-
-
-
printk(
"matt-ret1=%d,val=%x\n",ret,*tmp);
-
-
-
-
return ret;
-
-
}
-
-
EXPORT_SYMBOL(tlv320aic31_read);
-
-
/*void adv7180_Reset()
-
-
{
-
-
writel(0x00000000, IO_ADDRESS(0x200f00f4));
-
-
writel(0x00000008, IO_ADDRESS(0x201f0400));
-
-
writel(0x00000000, IO_ADDRESS(0x201f0020));
-
-
msleep(10);
-
-
writel(0x000000FF, IO_ADDRESS(0x201f0020));
-
-
}*/
-
-
-
-
-
-
static
int __
init tlv320aic31_init(void)
-
-
{
-
-
struct i2c_adapter* i2c_adap=NULL;
-
-
int temp =
0;
-
-
u8 val1=
0;
-
-
-
-
printk(
"matt-tlv320aic31_init+1\n");
-
-
//adv7180_Reset();
-
-
-
-
// use i2c2
-
-
i2c_adap = i2c_get_adapter(
2);
-
-
tlv_client = i2c_new_device(i2c_adap, &hi_info);
-
-
-
-
i2c_put_adapter(i2c_adap);
-
-
-
-
temp = tlv320aic31_write(
0x40,
0x00,
0x03);
-
-
printk(
"matt-temp=%x\n",temp);
-
-
temp = tlv320aic31_read(
0x40,
0x00);
-
-
-
-
printk(
"matt-temp1=%x\n",temp);
-
-
return
0;
-
-
}
-
-
-
-
static
void __
exit tlv320aic31_exit(void)
-
-
{
-
-
i2c_unregister_device(tlv_client);
-
-
-
-
printk(
"rmmod tlv320aic31.ko for Hi3516A ok!\n");
-
-
}
-
-
-
-
module_init(tlv320aic31_init);
-
-
module_exit(tlv320aic31_exit);
-
-
MODULE_LICENSE(
"GPL");
-
-
MODULE_AUTHOR(
"Hisilicon");
这是最简单版本