1. 程式人生 > >am335x系統升級之kernel i2c rtc eeprom(六)

am335x系統升級之kernel i2c rtc eeprom(六)

首先要明白一點,就是i2c裝置是掛載在總線上的,所以一定得先先加入匯流排驅動,現加裝置驅動。

雖然是初步接觸dts,也不懂dts的語法,但是之前有過豐富的驅動開發經驗,進行遷移:

對於i2c匯流排來說,有兩點需要注意的: 第一:引腳的初始化 第二:匯流排時鐘的設定

匯流排初始化第一點:

i2c0_pins: pinmux_i2c0_pins {
pinctrl-single,pins = <
AM33XX_IOPAD(0x988, PIN_INPUT_PULLUP | MUX_MODE0) /* i2c0_sda.i2c0_sda */
AM33XX_IOPAD(0x98c, PIN_INPUT_PULLUP | MUX_MODE0) /* i2c0_scl.i2c0_scl */


>;
};

如何得出引腳的初始化

  ->引腳初始化操作的肯定是PIN MUX暫存器

    ->然後檢視資料手冊,在其9.3章節當有有對CONTROL MODULES Register 的說明

      -->對比原理圖,0x988 0x98c就是CONTROL MODULES Register的偏移地址

 

匯流排初始化第二點:

&i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&i2c0_pins>;

status = "okay";
clock-frequency = <400000>;

匯流排成功初始化之後,就是要編寫 rtc (RX8025)及 eeprom (AT24C08)對應的節點,

針對i2c 裝置來說,最關鍵的就是i2c的地址資訊

我們可以參考核心的相關文件來編寫對應的dts結點,有了基於硬體特性的識認,就非常的簡單了:

Documentation/devicetree/bindings/rtc/epson,rx8900.txt

Documentation/devicetree/bindings/eeprom/eeprom.txt 

&i2c0 {
pinctrl-names = "default";
pinctrl-0 = <&i2c0_pins>;

status = "okay";
clock-frequency = <400000>;

tps: [email protected] {
reg = <0x2d>;
};

[email protected] {
compatible = "atmel,24c08";
pagesize = <16>;
reg = <0x50>;
};

[email protected] {
compatible = "epson,rx8025";
reg = <0x32>;
};

};

 

重新編寫,測試之後可得

[ 1.992222] at24 0-0050: 1024 byte 24c08 EEPROM, writable, 16 bytes/write
[ 2.000072] rtc-rx8025 0-0032: rx8025_get_time: read 0x40 0x59 0x05 0x02 0x27 0x11 0x18
[ 2.000092] rtc-rx8025 0-0032: rx8025_get_time: date 40s 59m 5h 27md 10m 118y
[ 2.000376] rtc rtc0: rx8025: dev (253:0)
[ 2.000407] rtc-rx8025 0-0032: rtc core: registered rx8025 as rtc0