简述ich7中spi总线flash rom的读写
2013-10-17 11:15
239 查看
ich7中spi总线flash rom的读写
=========================
1. 说明
x86主板上南桥芯片采用ich7,在ich7的spi总线上有一块eeprom,这块就是bios。
2. ich7 spi控制寄存器地址
ich7上的设备作为pci设备挂载在系统中,其中device 31、function 0是lpc。
也就是bus = 0, device = 0x1f, function = 0
其配置空间F0h存放RCBA。
spi控制寄存器对应的地址段为 0x3020 - 0x308f
用ioremap()映射这段空间到linux虚存空间,就可以控制spi控制寄存器了。
3. spi的控制寄存器
具体的请看ich7的datasheet
1> spis - spi status register
2> spic - spi control register
3> spia - spi address register
4> spid - spi data register
5> bbar - bios base address register
6> preop - prefix opcode configurationregister
7> optype - opcode type configuration register
8> opmenu - opcode menu configuration register
9> pbr
- protected bios range
spi总线是如何收发数据,这里不需要了解,只需要控制以上寄存器,它们会完成spi数据的收发。
4. spi控制寄存器初始化
主要初始化的寄存器如下
1> preop
software programs an spi opcode into this field that is premittedto run as the first command in an atomic cycle sequence.
在命令序列开始前会首先执行这个命令
比如,使用0x06,对应的是WREN写使能命令,在写操作之前就要先执行这个命令
2> optype
操作能行分四类
00 - 无需地址读操作
01 - 无需地址写操作
10 - 需地址读操作
11 - 需地址写操作
无需地址的操作一般都是读写状态寄存器等等
需地址的操作一般是读写数据的
3> opmenu
opcode有8组,也即是说只能进行这8种操作,对系统也是一种保护。
具体的命令需要看eeprom手册,一下列出几种:
write enable 06h
write disable 04h
read status register 05h
write status register 01h
read data bytes 03h
page program 02h
sector erase d8h
bulk erase c7h
5. 读写操作的执行
经过上面的初始化,下面直接控制spia spid spis spic就可以了
1> spia中写入需要操作数据地址偏移量
2> spid中写入需要传输的数据
3> spis中清除状态位0x4 0x8
4> spic中写入opmenu中匹配的命令,data长度,置位SCGO开始传输
5> 读取spis中状态位0x04 CDS或者0x01 SCIP,等待操作完成
注:對於 write device command (Ex. WREN,WRSR,PROGRAM,ERASE..)你有再多 check device端的 status register嗎 ? 別忘了 device端仍有 status (InProgress)要check
所以,"pseudo code" is:
1.put the opcode into the OPMENU buffer
2.set the opcode type
3.If ( Address is required )
Then set the SPI Address field
Else clear SPI Address field
4.set the cycle opcode pointer
5.If ( WREN is needed )
Then set ACS, put WREN opcode, and set Sequence Prefix Opcode Pointer
Else clear ACS
6.If ( Data is involved )
Then set Data Cycle and DBC
Else clear Data Cycle
7.If ( Host write data to device )
Then put data into SPI DATA registers
8.set Cycle Go bit to initiate the transfer
9.2-phase status check ( both host and device )
10.clear status
PS:由于是bios芯片,操作一定要十分谨慎。
=========================
1. 说明
x86主板上南桥芯片采用ich7,在ich7的spi总线上有一块eeprom,这块就是bios。
2. ich7 spi控制寄存器地址
ich7上的设备作为pci设备挂载在系统中,其中device 31、function 0是lpc。
也就是bus = 0, device = 0x1f, function = 0
其配置空间F0h存放RCBA。
spi控制寄存器对应的地址段为 0x3020 - 0x308f
用ioremap()映射这段空间到linux虚存空间,就可以控制spi控制寄存器了。
3. spi的控制寄存器
具体的请看ich7的datasheet
1> spis - spi status register
2> spic - spi control register
3> spia - spi address register
4> spid - spi data register
5> bbar - bios base address register
6> preop - prefix opcode configurationregister
7> optype - opcode type configuration register
8> opmenu - opcode menu configuration register
9> pbr
- protected bios range
spi总线是如何收发数据,这里不需要了解,只需要控制以上寄存器,它们会完成spi数据的收发。
4. spi控制寄存器初始化
主要初始化的寄存器如下
1> preop
software programs an spi opcode into this field that is premittedto run as the first command in an atomic cycle sequence.
在命令序列开始前会首先执行这个命令
比如,使用0x06,对应的是WREN写使能命令,在写操作之前就要先执行这个命令
2> optype
操作能行分四类
00 - 无需地址读操作
01 - 无需地址写操作
10 - 需地址读操作
11 - 需地址写操作
无需地址的操作一般都是读写状态寄存器等等
需地址的操作一般是读写数据的
3> opmenu
opcode有8组,也即是说只能进行这8种操作,对系统也是一种保护。
具体的命令需要看eeprom手册,一下列出几种:
write enable 06h
write disable 04h
read status register 05h
write status register 01h
read data bytes 03h
page program 02h
sector erase d8h
bulk erase c7h
5. 读写操作的执行
经过上面的初始化,下面直接控制spia spid spis spic就可以了
1> spia中写入需要操作数据地址偏移量
2> spid中写入需要传输的数据
3> spis中清除状态位0x4 0x8
4> spic中写入opmenu中匹配的命令,data长度,置位SCGO开始传输
5> 读取spis中状态位0x04 CDS或者0x01 SCIP,等待操作完成
注:對於 write device command (Ex. WREN,WRSR,PROGRAM,ERASE..)你有再多 check device端的 status register嗎 ? 別忘了 device端仍有 status (InProgress)要check
所以,"pseudo code" is:
1.put the opcode into the OPMENU buffer
2.set the opcode type
3.If ( Address is required )
Then set the SPI Address field
Else clear SPI Address field
4.set the cycle opcode pointer
5.If ( WREN is needed )
Then set ACS, put WREN opcode, and set Sequence Prefix Opcode Pointer
Else clear ACS
6.If ( Data is involved )
Then set Data Cycle and DBC
Else clear Data Cycle
7.If ( Host write data to device )
Then put data into SPI DATA registers
8.set Cycle Go bit to initiate the transfer
9.2-phase status check ( both host and device )
10.clear status
PS:由于是bios芯片,操作一定要十分谨慎。
相关文章推荐
- SPI学习(SPI总线读写FLASH)
- Linux下SPI总线驱动分析
- zedboard如何从PL端控制DDR读写(三)——AXI-FULL总线调试
- 读写SPI FLASH--应用程序部分
- SPI、I2C、UART三种串行总线的原理、区别及应用
- CAN、USART、SPI、SCI等常见总线技术介绍
- SPI总线规范
- Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
- CAN总线简述
- SPI、I2C、UART三种串行总线的区别
- Linux SPI总线和设备驱动架构之四:SPI数据传输的队列化
- SPI总线驱动
- 一种特殊的SPI读写
- spi总线
- SPI、I2C、UART三种串行总线协议的区别
- Linux spi驱动分析(一)----总线驱动
- SPI总线之CPOL CPHA
- TinyOS 再论FLASH与SPI总线问题
- SPI总线的工作方式和特点
- uart,spi,i2c, can 总线的区别