static const struct i2c_algorithm hi_i2c_algo
= {
.master_xfer
= hi_i2c_xfer
,
.functionality
= hi_i2c_func
,
};
static int hi_i2c_xfer(struct i2c_adapter
*adap
, struct i2c_msg
*msgs
,
int num
)
{
struct hi_i2c
*pinfo
;
int errorcode
;
pinfo
= (struct hi_i2c
*)i2c_get_adapdata(adap
);
pinfo
->msgs
= msgs
;
pinfo
->msg_num
= num
;
pinfo
->msg_index
= 0;
if (msgs
->flags
& I2C_M_RD
)
errorcode
= hi_i2c_read(pinfo
);
else
errorcode
= hi_i2c_write(pinfo
);
return errorcode
;
}
int hi_i2c_write(struct hi_i2c
*pinfo
)
{
unsigned int reg_val
;
unsigned int temp_reg
;
unsigned int temp_data
;
unsigned int temp_auto_reg
;
struct i2c_msg
*msgs
= pinfo
->msgs
;
if (hi_i2c_set_dev_addr_and_mode(pinfo
, I2C_MODE_AUTO
) < 0)
return -1;
temp_auto_reg
= HI_I2C_WRITE
;
if (msgs
->flags
& I2C_M_16BIT_REG
) {
temp_auto_reg
|= I2C_AUTO_ADDR
;
temp_reg
= msgs
->buf
[pinfo
->msg_index
] << 8;
pinfo
->msg_index
++;
temp_reg
|= msgs
->buf
[pinfo
->msg_index
];
pinfo
->msg_index
++;
} else {
temp_reg
= msgs
->buf
[pinfo
->msg_index
];
pinfo
->msg_index
++;
}
if (msgs
->flags
& I2C_M_16BIT_DATA
) {
temp_auto_reg
|= I2C_AUTO_DATA
;
temp_data
= msgs
->buf
[pinfo
->msg_index
] << 8;
pinfo
->msg_index
++;
temp_data
|= msgs
->buf
[pinfo
->msg_index
];
pinfo
->msg_index
++;
} else {
temp_data
= msgs
->buf
[pinfo
->msg_index
];
pinfo
->msg_index
++;
}
writel(temp_auto_reg
, pinfo
->regbase
+ I2C_AUTO_REG
);
hi_msg("temp_auto_reg: 0x%x\n", temp_auto_reg
);
reg_val
= (temp_reg
<< REG_SHIFT
) | temp_data
;
if (hi_i2c_wait_txfifo_notfull(pinfo
) < 0)
return -1;
hi_msg("reg_val = %x\n", reg_val
);
writel(reg_val
, pinfo
->regbase
+ I2C_TX_RX_REG
);
hi_msg("dev_addr =%x, reg_addr = %x, Data = %x\n",
pinfo
->msgs
->addr
, pinfo
->msgs
->buf
[0], pinfo
->msgs
->buf
[1]);
return pinfo
->msg_index
;
}
hi_i2c_set_dev_addr_and_mode
hi_i2c_wait_idle
hi_i2c_wait_txfifo_notfull
目前还没找到I2C的fifo缓冲的资料
http://blog.csdn.net/ljzcom/article/details/9342859
http://www.cnblogs.com/BitArt/archive/2013/05/27/3101037.html
http://blog.csdn.net/goodwillyang/article/details/46272207
转载请注明原文地址: https://ju.6miu.com/read-200218.html