static
const
struct i2c_algorithm hi_i2c_algo =
;//這個結構體是驅動端的.通過adapter?適配到device端
//也就是說在匯流排上建立乙個device,最終會呼叫到這個結構體裡面的函式
static
inthi_i2c_xfer
(struct i2c_adapter *adap,
struct i2c_msg *msgs,
int num)
//這個函式是用來被呼叫的.在i2c-core.c裡面呼叫的就是這類xfer函式.而這個函式只是對應某個驅動的函式
int
hi_i2c_write
(struct hi_i2c *pinfo)
else
if(msgs->flags & i2c_m_16bit_data)
else
writel
(temp_auto_reg, pinfo->regbase + i2c_auto_reg)
;hi_msg
("temp_auto_reg: 0x%x\n"
, temp_auto_reg)
;/* set write reg&data */
reg_val =
(temp_reg << reg_shift)
| temp_data;
/* wait until tx fifo not full */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_write函式,因為呼叫這個函式出問題了.
hi_i2c_set_dev_addr_and_mode
hi_i2c_wait_idle//等待tx rx 緩衝器都空了,且讀取初始化暫存器
//寫一些暫存器
//設定模式
//使能i2c
//設定i2c_auto_reg
hi_i2c_wait_txfifo_notfull/* wait until tx fifo is not full */
//設定i2c_tx_rx_reg
目前還沒找到i2c的fifo緩衝的資料/*
上面是一次寫的過程.
問題是第一次寫正常,第二次寫
hi_i2c_wait_txfifo_notfull 返回失敗
並列印了
hi_i2c_wait_txfifo_notfull->262:
transmit error, int_raw_satatus: 0x750!
hi_i2c_wait_txfifo_notfull->264:
tx_abrt_cause is 1.
*/
i2c匯流排時序
一心想踏入linux device driver的世界,想著i2c匯流排相對於usb等其他匯流排較為簡單,就以i2c作為切入點,希望可以逐步理解ldd的設計思想,並能理解其裝置模型的概念。在此對近期於i2c匯流排及驅動原始碼的理解做備忘,以免徒勞。平台友善之臂s70 tiny6410 cpusams...
I2C匯流排死鎖
原文 現象 最近發現訪問i2c裝置時,主裝置復位可能會引起i2c死鎖,表現為scl為高,sda一直為低,後發現是從裝置拉死i2c匯流排,從裝置斷電之後,sda變高,上電後通訊正常。後來通過拉低scl訊號線,sda就會自動變成高電平,i2c匯流排恢復。原因 在正常情況下,i2c匯流排協議能夠保證匯流排...
I 2C匯流排簡介
總共有五種工作狀態 a 匯流排非忙狀態 該狀態時資料線 sda 和時鐘線 scl 都保持高電平。b 啟動狀態 當時鐘線 scl 為高電平狀態時,資料線 sda 由高電平變為低電平的下降沿被認為是 啟動 訊號。c 停止狀態 當時鐘線 scl 為高電平狀態時,資料線 sda 由低電平變為高電平的下降沿被...